I FOUND the solution in this way .
I created a cron which copy /etc/shadow in /etc/shadow2 .
shadow2 is readable so I can work with it .
With following code .......
- Code: Select all
<?php
$user ='test';
$password ='testpwd';
$passwdFile='/etc/shadow2';
$users=file($passwdFile);
if (!$user=preg_grep("/^$userName/",$users))
{
echo "User '$userName' not found!";
}
else
{
list(,$passwdInDB)=explode(':',array_pop($user));
if (crypt($userPasswd,$passwdInDB) == $passwdInDB)
{
echo "Password verified!";
}
else
{
echo "Passwords don't match!";
}
}
?>
......I solve the problem , however there is still something wrong on it .
This line ...
- Code: Select all
list(,$passwdInDB)=explode(':',array_pop($user));
if (crypt($userPasswd,$passwdInDB) == $passwdInDB)
should search the user ($user) and crypt the password after :
It works , but instead to get the $user it get the LAST user
in the list .
For example ... if the list contained in /etc/shadow2 is ;
useralfa:ZqrYf9Sia4xz6:11906::::::
userbravo:9IpB2JN0oVAUA:11912::::::
usercharlie:9IpB2JN0oVAUA:11912::::::
and I insert $user= 'userbravo';
the code crypt the user usercharlie instead of userbravo .
Can you find the error ?
thank you.