lkml.org 
[lkml]   [1999]   [Aug]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: password encryption
On Tue, 3 Aug 1999, ywlee wrote:

> hi,
>
> how do I implement a encryption algorithm for a password in C?
> I'm writing this code in Linux. I have tried to use the crypt()
> function from unistd.h but I cannot compile because of undefined
> reference. Please help. :)
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.rutgers.edu
> Please read the FAQ at http://www.tux.org/lkml/
>

See attached code to generate encrypted passwd's. It should generalize
well enough.

rgb

Robert G. Brown http://www.phy.duke.edu/~rgb/
Duke University Dept. of Physics, Box 90305
Durham, N.C. 27708-0305
Phone: 1-919-660-2567 Fax: 919-660-2525 email:rgb@phy.duke.edu

#%< Snip Snip Snip ====================================================
#include <stdio.h>
#include <stdlib.h>

static char rcs_id[]="$Id: makepw.c,v 1.1.1.1 1998/10/15 05:46:33 rgb Exp $ (Robert G. Brown)";

char *crypt();

main(argc, argv)
int argc;
char **argv;
{
char *s,passwd[128],salt[8];
unsigned long i,iterations;
if(argc != 3) {
fprintf(stderr, "usage: makepw passwd salt\n");
exit(1);
}
argv++;
sprintf(passwd,"%s",*argv);
/* Truncate passwd at eight characters on general principles.*/
passwd[8] = 0;
argv++;
sprintf(salt,"%s",*argv);
/* Truncate salt at two characters, ditto. */
salt[2] = 0;
s=crypt(passwd,salt);
printf("%s\n",s);
exit(0);
}


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:53    [from the cache]
©2003-2011 Jasper Spaans