Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!europa.asd.contel.com!noc.sura.net!mars!orion!quillen From: quillen@orion.fccc.edu (John Quillen) Newsgroups: comp.unix.wizards Subject: Re: opening accounts from a non-root account .. Summary: How to use crypt(3) Keywords: password, crypt(3) Message-ID: <1991Jun14.135823.27059@fccc.edu> Date: 14 Jun 91 13:58:23 GMT References: Sender: news@fccc.edu (USENET News System) Distribution: comp.unix.wizards Organization: Fox Chase Cancer Center, Philadelphia PA Lines: 51 Nntp-Posting-Host: relay.fccc.edu >lubkt@spectrum.CC.Lehigh.EDU (Binod K. Taterway) writes... > >DES, and a host of other programs. I realize crypt cannot generate >initial encrypted password because it doesn't have the right seed. Let >EPW be the encrypted password of the clear-text password, PW. Then, > > EPW = crypt(PW, EPW) Crypt can, in fact, generate the right password. The "seed" is better known as the salt (man 3 crypt for an explanation). The salt appears as the first two characters of the encrypted string. That is how multiple users can have the same password and unique encrypted passwords. Here's a code fragment you may find useful... John #include /* call once before making getrand calls */ #define seedrand() srand( (int) time( 0 ) + getpid() ) /* generate random number in given range */ #define getrand( lo, hi ) (( rand() % ( hi - lo )) + lo ) /* * mk_pass - generate encrypted string passwd */ char * mk_pass( pass ) char *pass; /* unencrypted passwd */ { extern char *crypt(); char salt[ 3 ]; salt[ 0 ] = (char) getrand( 'a', 'z' ); salt[ 1 ] = (char) getrand( 'A', 'Z' ); salt[ 2 ] = (char) NULL; return( crypt( pass, salt )); } -- -------------------------------------------------------------------------- John W. Quillen, Jr. Phone: (215) 728-3660 Research Computing Services FAX: (215) 728-3574 The Fox Chase Cancer Center internet: JW_Quillen@fccc.edu 7701 Burholme Avenue /----------------------------------------- Philadelphia, PA 19111 / "No matter where you go, there you are." USA / - B. Banzai --------------------------------------------------------------------------