| 1 |
<? |
<?php |
| 2 |
function verify_pass_complexity($password, $username, $min_len) |
function verify_pass_complexity($password, $username, $min_len) |
| 3 |
{ |
{ |
|
$ch = array(); |
|
| 4 |
$num_count = 0; |
$num_count = 0; |
| 5 |
$upper_case = 0; |
$upper_case = 0; |
| 6 |
$lower_case = 0; |
$lower_case = 0; |
| 11 |
return false; |
return false; |
| 12 |
} |
} |
| 13 |
|
|
| 14 |
if (strstr(strtoupper($password), strtoupper($username)) !== false) |
if (stristr($password, $username) !== false) |
| 15 |
{ |
{ |
| 16 |
return false; |
return false; |
| 17 |
} |
} |
| 19 |
for ($i = 0; $i < $len; $i++) |
for ($i = 0; $i < $len; $i++) |
| 20 |
{ |
{ |
| 21 |
$c = $password[$i]; |
$c = $password[$i]; |
|
|
|
|
if (isset($ch[$c])) |
|
|
{ |
|
|
$ch[$c]++; |
|
|
if ($ch[$c] >= 3) |
|
|
{ |
|
|
return false; |
|
|
} |
|
|
} |
|
|
else |
|
|
{ |
|
|
$ch[$c] = 1; |
|
|
} |
|
| 22 |
|
|
| 23 |
if (is_numeric($c)) |
if (is_numeric($c)) |
| 24 |
{ |
{ |
| 25 |
$num_count++; |
$num_count++; |
|
if ($num_count >= 3) |
|
|
{ |
|
|
return false; |
|
|
} |
|
| 26 |
} |
} |
| 27 |
|
|
| 28 |
if (ord($c) >= ord('A') && ord($c) <= ord('Z')) |
if (ctype_upper($c)) |
| 29 |
{ |
{ |
| 30 |
$upper_case++; |
$upper_case++; |
| 31 |
} |
} |
| 32 |
|
|
| 33 |
if (ord($c) >= ord('a') && ord($c) <= ord('z')) |
if (ctype_lower($c)) |
| 34 |
{ |
{ |
| 35 |
$lower_case++; |
$lower_case++; |
| 36 |
} |
} |
| 37 |
} |
} |
| 38 |
|
|
| 39 |
if ($upper_case==0 || $lower_case==0 || $num_count==0) |
if ($upper_case == 0 || $lower_case == 0 || $num_count == 0) |
| 40 |
{ |
{ |
| 41 |
return false; |
return false; |
| 42 |
} |
} |
| 54 |
$num = mt_rand(0, 61); |
$num = mt_rand(0, 61); |
| 55 |
$str .= chr($num < 10 ? (ord("0") + $num) : ($num < 36 ? (ord("A") + $num - 10) : (ord("a") + $num - 36))); |
$str .= chr($num < 10 ? (ord("0") + $num) : ($num < 36 ? (ord("A") + $num - 10) : (ord("a") + $num - 36))); |
| 56 |
} |
} |
| 57 |
|
|
| 58 |
return $str; |
return $str; |
| 59 |
} |
} |
|
|
|
|
?> |
|