after searching web for very simple, nice working php password checker i couldn't find any good solution for my needs,
so i decided to code my own password strength checker,
some function parts were taken from functions which ive found but they were not good enough for me.
here is a function:
if someone has better functions please share here.
so i decided to code my own password strength checker,
some function parts were taken from functions which ive found but they were not good enough for me.
here is a function:
PHP Code:
function check_password_strength($password)
{
$score = array("Blank","Very Weak","Weak","Medium","Strong","Very Strong");
$strength = password_strength_score($password);
return $score[$strength-1];
}
function password_strength_score($password)
{
$strength = 0;
$length = strlen($password);
if ($length < 1)
return 1;
elseif ($length < 4)
return 2;
else $strength = 1;
$clean_string = preg_replace('/[^[:alnum:]]/i', '', $password);
if(strlen($clean_string) != $length) $strength++;
elseif($length < 5) return 2;
if(($length - strlen($clean_string))>1)
$strength++;
if ($length > 7)
$strength++;
$patterns = array("#[a-z]#","#[A-Z]#","#[0-9]#");
foreach($patterns AS $pattern)
{
if(preg_match($pattern,$password))
{
$strength++;
}
}
if($strength>6)$strength=6;
return $strength;
}
Comment