首页 > 开发 > PHP > 正文

用户口令检查(/etc/passwd)

2024-05-04 23:05:03
字体:
来源:转载
供稿:网友
<?
/*
* etc.passwd.inc v1.0
*
* syntax:
* verifypasswd(string username, string password)
*
* the function will return one of three values:
* -2 if there was a file reading error
* -1 if the password is incorrect
* 0 if the username doesn't exist
* 1 if the password is correct
*
* written by warmage ( [email protected] )
*
*/

function verifypasswd ($username, $password) {

$fd = fopen( "/etc/passwd", "r");
$contents = fread($fd, filesize( "/etc/passwd"));
fclose($fd);
if (!$contents) return -2;



$lines = split( "/n", $contents);
$passwd = array();

for($count=0;$count<count($lines);$count++) {
list ($user,$pass) = split( ":",$lines[$count]);
if ($user == $username) {
break;
}
}

if (!$user) return 0;

$cryptedpass = $pass;
$salt = substr($cryptedpass,0,2);
$pass = crypt($password,$salt);

if ($pass == $cryptedpass) {
return 1;
} else {
return -1;
}
}
?>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表