Heim  >  Artikel  >  Backend-Entwicklung  >  用户口令检查(/etc/passwd)_PHP教程

用户口令检查(/etc/passwd)_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:09:061058Durchsuche


/*
* 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
*/

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 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;
}
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/629775.htmlTechArticle? /* * 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 * -...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:PHP代码加密解密一法_PHP教程Nächster Artikel:php 防注入_PHP教程