home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / alt / hackers / 1150 < prev    next >
Encoding:
Text File  |  1992-07-23  |  1.9 KB  |  58 lines

  1. Path: sparky!uunet!utcsri!devnull
  2. Newsgroups: alt.hackers
  3. From: flaps@dgp.toronto.edu (Alan J Rosenthal)
  4. Subject: Re: /etc/passwords
  5. Message-ID: <1992Jul23.110110.15268@jarvis.csri.toronto.edu>
  6. References: <Brt4nI.IFw@undergrad.math.waterloo.edu>
  7. Date: 23 Jul 92 15:01:10 GMT
  8. Approved: AT&T
  9. Lines: 47
  10.  
  11. nimouat@napier.waterloo.edu (Nikos Mouat) writes:
  12. >What kind of encoding scheme is used, is it RSA?
  13.  
  14. no, it's des with some variant and a weird approach in that the password is
  15. used as the key rather than the message, or something like that.  It antedates
  16. RSA by like two decades!  I forget the details of what it is, but here's how to
  17. use it from C, given the C library function crypt():
  18.  
  19. crypt() takes two parameters both of which are (char *)s, the first being the
  20. password you want to encrypt and the second being a two-character salt.  The
  21. field in /etc/passwd is this salt concatenated with the encrypted password,
  22. which is the return value of crypt().
  23.  
  24. The upshot is this:  If p is a pointer to struct passwd from the password
  25. file, you do something like this:
  26.  
  27.     if (strcmp(crypt(typedpasswd, p->pw_passwd), p->pw_passwd))
  28.         ... they typed the wrong passwd.
  29.  
  30. That crypt() call can actually be crypt(getpass("Password:"), p->pw_passwd) if
  31. you want it to prompt the user.  getpass() is a very cool library function
  32. which turns off echo, prompts the user, gets the password, outputs a newline,
  33. turns echo back on again.
  34.  
  35. If you want to make some /etc/passwd passwd fields of your own, this is how you
  36. do it.
  37.  
  38.     char *cryptpasswd(passwd)
  39.         char *passwd;
  40.     {
  41.         long salttime, time();
  42.         char dessalt[2], *crypt();
  43.         int i;
  44.  
  45.         time(&salttime);
  46.         dessalt[0] = salttime & 63;
  47.         dessalt[1] = (salttime >> 6) & 63;
  48.         for (i = 0; i < 2; i++) {
  49.         dessalt[i] += '.';
  50.         if (dessalt[i] > '9')
  51.             dessalt[i] += 7;
  52.         if (dessalt[i] > 'Z')
  53.             dessalt[i] += 6;
  54.         }
  55.  
  56.         return(crypt(passwd, dessalt));
  57.     }
  58.