計算密碼強度的php代碼
<?php /**
- @param String $string
- @return float
- Returns a float between 0 and 100. The closer the number is to 100 the
- the stronger password is; further from 100 the weaker the password is.
*/
function password_strength($string){
$h = 0;
$size = strlen($string);
foreach(count_chars($string, 1) as $v){
} $strength = ($h / 4) * 100; if($strength > 100){$p = $v / $size; $h -= $p * log($p) / log(2);
} return $strength; }$strength = 100;
var_dump(password_strength("Correct Horse Battery Staple"));
echo "<br>";
var_dump(password_strength("Super Monkey Ball"));
echo "<br>";
var_dump(password_strength("Tr0ub4dor&3"));
echo "<br>";
var_dump(password_strength("abc123"));
echo "<br>";
var_dump(password_strength("sweet"));</pre>
本文由用戶 ded3b 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!