> 백엔드 개발 > PHP 튜토리얼 > 用户口令检查_PHP

用户口令检查_PHP

WBOY
풀어 주다: 2016-06-01 12:31:36
원래의
1176명이 탐색했습니다.
<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>
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿