home *** CD-ROM | disk | FTP | other *** search
/ H4CK3R 4 / hacker04 / 04_HACK04.ISO / src / PHP / etc.passwd.inc.txt < prev    next >
Encoding:
Text File  |  2002-05-06  |  1.3 KB  |  51 lines

  1. <? 
  2. /* 
  3.  * etc.passwd.inc v1.0 
  4.  * etc.passwd.inc 
  5.  * Authentication function that checks a user/pass against /etc/passwd 
  6.  * Syntax: 
  7.  *    verifypasswd(string USERNAME, string PASSWORD) 
  8.  * 
  9.  * The function will return one of three values: 
  10.  *    -2 if there was a file reading error 
  11.  *    -1 if the password is incorrect 
  12.  *     0 if the username doesn't exist 
  13.  *     1 if the password is correct 
  14.  * 
  15.  * Written by WarMage (michael@irc.net) 
  16.  * 
  17.  */ 
  18.  
  19. function verifypasswd ($USERNAME, $PASSWORD) { 
  20.  
  21.         $fd = fopen( "/etc/passwd",  "r"); 
  22.         $contents = fread($fd, filesize( "/etc/passwd")); 
  23.         fclose($fd); 
  24.         if (!$contents) return -2; 
  25.  
  26.  
  27.  
  28.         $lines = split( "\n", $contents); 
  29.         $passwd = array(); 
  30.  
  31.         for($count=0;$count<count($lines);$count++) { 
  32.                 list ($user,$pass) = split( ":",$lines[$count]); 
  33.                 if ($user == $USERNAME) { 
  34.                         break; 
  35.                 } 
  36.         } 
  37.  
  38.         if (!$user) return 0; 
  39.  
  40.         $cryptedpass = $pass; 
  41.         $salt = substr($cryptedpass,0,2); 
  42.         $Pass = crypt($PASSWORD,$salt); 
  43.  
  44.         if ($Pass == $cryptedpass) { 
  45.                 return 1; 
  46.         } else { 
  47.                 return -1; 
  48.         } 
  49. ?> 
  50.