Categories
Concept/algorithm Operating System PHP

Linux User authentication using PHP

In one of my last post i try to define how linux store its password. Today I will be putting Complete PHP code for it.

Just run it on your local server(mind it your Http server must be running as root user in order to use this script )

Its a raw way of doing password matching and shouldn’t be used for commerical application or servers. its purely Learning script

So here goes the script

6 && CRYPT_MD5 == 1) {
$salts = explode(“$”,”$userlist[1]”);
$salt = “\$1\$”.$salts[2].”\$”;
$gen_password= crypt($password,$salt);
if ($gen_password == $userlist[1]) {
$UserMatch = true;
}
else
{
$UserMatch = false;
}
}
else {
$UserMatch = false;
}
break;
}
}
return $UserMatch ;
}

if (ReadUser(“sumit”) == true)
{
if (MatchPassword(“sumit”,”sumit”) == true )
{
echo “Login successful”;
}
else
{
echo “Login unsuccessful”;
}
}
?>

Hope that helps learn understanding linux passwd and shadow usage.

EDIT: I will update the script sometime sooner maybe!!!

By Sumit Gupta

Sumit Gupta, a developer by choice.

2 replies on “Linux User authentication using PHP”

I observe that it is incomplete. I have to look it in detail will do that, just want to tell that it miss the “IF” condition which actually is checking for Crypt function and its type.

Comments are closed.