note 49191 added to function.crypt
| From: | pietheinatstrengholt-onlinedotnl at osu1 dot php dot net | Date: | Wed, 19 Jan 2005 15:21:06 +0000 |
| Subject: | note 49191 added to function.crypt | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-83631@lists.php.net to get a copy of this message | ||
I'm trying to create a script using the files /etc/passwd and /etc/shadow to give system users
access on my linux machine.
To not give all users access and to protect the files I'm using a perl script to generate a
file with the passwords and usernames:
Perl Script:
#!/usr/bin/perl
#
open(PASSWD,"/etc/passwd");
open(SHADOW,"/etc/shadow");
open(FLATFILE,">/etc/passwd.httpd");
while(<SHADOW>){
chop;
($uname,$temppass)=split(/:/);
$pass{$uname}=$temppass;
}
while(<PASSWD>){
chop;
($uname,$temppass,$uid,$gid,$fn,$homedir,$shell)=split(/:/);
if ($temppass ne 'x'){ $pass{$uname}=$temppass; }
if ($uid>=500) {
print FLATFILE
"$uname:$pass{$uname}:$uid:$gid:$fn:$homedir:$shell\n";
}
}
close(PASSWD);
close(SHADOW);
close(FLATFILE);
chmod(0400,"/etc/passwd.httpd");
chown(65534,65534,"/etc/passwd.httpd");
Below is the php script which should give users access. The output of the password should match the
password hash in the perl generated file:
<?php
$user = ($_POST['username']);
$password = ($_POST['password']);
$autharray = file("/home/httpd/vhosts/domein.nl/httpdocs/passwd.httpd");
for ($x = 0; $x < count($autharray); $x++)
{
if (eregi("^$user:", $autharray[$x]))
{
$passwd = explode(":", $autharray[$x]);
$salt = substr($passwd[1],0,2);
$cryptpw = crypt($pass,$salt);
if ($cryptpw == $passwd[1]) {
print "succes";
} else {
print "fout";
}
}
}
?>
I tried the script as posted above, but this gives me random hashes like:
$1$dc.cNxen$B7xUcH/RxAvJkBw5BABuz/
$1$rICJiYRz$frLxNIiD3ue7YP9BN2Wdr1
$1$FkqAPyXv$wue8h8D2B.vButyL/krXR0
does anyone of you know what could be wrong? What do I need to change to the script to make it work?
----
Manual Page -- http://www.php.net/manual/en/function.crypt.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49191
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49191&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49191&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49191&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49191&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49191&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49191&report=yes
Search -- http://master.php.net/manage/user-notes.php