Home >Backend Development >PHP Tutorial >用户口令检查_PHP

用户口令检查_PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-01 12:31:361234browse
<font color="#000000"> <font color="#0000BB"></font><font color="#007700"> <br></font><font color="#FF8000">/* <br>* etc.passwd.inc v1.0 <br>* <br>* Syntax: <br>* verifypasswd(string USERNAME, string PASSWORD) <br>* <br>* The function will return one of three values: <br>* -2 if there was a file reading error <br>* -1 if the password is incorrect <br>* 0 if the username doesn't exist <br>* 1 if the password is correct <br>* <br>* Written by WarMage ( michael@irc.net ) <br>* <br>*/ <br><br></font><font color="#007700">function </font><font color="#0000BB">verifypasswd </font><font color="#007700">(</font><font color="#0000BB">$USERNAME</font><font color="#007700">, </font><font color="#0000BB">$PASSWORD</font><font color="#007700">) { <br><br></font><font color="#0000BB">$fd </font><font color="#007700">= </font><font color="#0000BB">fopen</font><font color="#007700">( </font><font color="#DD0000">"/etc/passwd"</font><font color="#007700">, </font><font color="#DD0000">"r"</font><font color="#007700">); <br></font><font color="#0000BB">$contents </font><font color="#007700">= </font><font color="#0000BB">fread</font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">, </font><font color="#0000BB">filesize</font><font color="#007700">( </font><font color="#DD0000">"/etc/passwd"</font><font color="#007700">)); <br></font><font color="#0000BB">fclose</font><font color="#007700">(</font><font color="#0000BB">$fd</font><font color="#007700">); <br>if (!</font><font color="#0000BB">$contents</font><font color="#007700">) return -</font><font color="#0000BB">2</font><font color="#007700">; <br><br><br><br></font><font color="#0000BB">$lines </font><font color="#007700">= </font><font color="#0000BB">split</font><font color="#007700">( </font><font color="#DD0000">"\n"</font><font color="#007700">, </font><font color="#0000BB">$contents</font><font color="#007700">); <br></font><font color="#0000BB">$passwd </font><font color="#007700">= array(); <br><br>for(</font><font color="#0000BB">$count</font><font color="#007700">=</font><font color="#0000BB">0</font><font color="#007700">;</font><font color="#0000BB">$count</font><font color="#007700"><font color="#0000BB">count</font><font color="#007700">(</font><font color="#0000BB">$lines</font><font color="#007700">);</font><font color="#0000BB">$count </font><font color="#007700">) { <br>list (</font><font color="#0000BB">$user</font><font color="#007700">,</font><font color="#0000BB">$pass</font><font color="#007700">) = </font><font color="#0000BB">split</font><font color="#007700">( </font><font color="#DD0000">":"</font><font color="#007700">,</font><font color="#0000BB">$lines</font><font color="#007700">[</font><font color="#0000BB">$count</font><font color="#007700">]); <br>if (</font><font color="#0000BB">$user </font><font color="#007700">== </font><font color="#0000BB">$USERNAME</font><font color="#007700">) { <br>break; <br>} <br>} <br><br>if (!</font><font color="#0000BB">$user</font><font color="#007700">) return </font><font color="#0000BB">0</font><font color="#007700">; <br><br></font><font color="#0000BB">$cryptedpass </font><font color="#007700">= </font><font color="#0000BB">$pass</font><font color="#007700">; <br></font><font color="#0000BB">$salt </font><font color="#007700">= </font><font color="#0000BB">substr</font><font color="#007700">(</font><font color="#0000BB">$cryptedpass</font><font color="#007700">,</font><font color="#0000BB">0</font><font color="#007700">,</font><font color="#0000BB">2</font><font color="#007700">); <br></font><font color="#0000BB">$Pass </font><font color="#007700">= </font><font color="#0000BB">crypt</font><font color="#007700">(</font><font color="#0000BB">$PASSWORD</font><font color="#007700">,</font><font color="#0000BB">$salt</font><font color="#007700">); <br><br>if (</font><font color="#0000BB">$Pass </font><font color="#007700">== </font><font color="#0000BB">$cryptedpass</font><font color="#007700">) { <br>return </font><font color="#0000BB">1</font><font color="#007700">; <br>} else { <br>return -</font><font color="#0000BB">1</font><font color="#007700">; <br>} <br>} <br></font><font color="#0000BB">?></font></font> </font>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn