PDA

Click to See Complete Forum and Search --> : [PHP] Check Password Strength


john tindell
Feb 8th, 2006, 01:03 PM
Checks the strength of a password and return an integer value depening on it's strength


function CheckPasswordStrength($password)
{

$strength = 0;
$patterns = array('#[a-z]#','#[A-Z]#','#[0-9]#','/[¬!"£$%^&*()`{}\[\]:@~;\'#<>?,.\/\\-=_+\|]/');
foreach($patterns as $pattern)
{
if(preg_match($pattern,$password,$matches))
{
$strength++;
}
}
return $strength;

// 1 - weak
// 2 - not weak
// 3 - acceptable
// 4 - strong
}

//usage
CheckPasswordStrength('password'); //1
CheckPasswordStrength('Password'); //2
CheckPasswordStrength('P4ssword'); //3
CheckPasswordStrength('P4ssw()rd'); //4

penagate
Feb 10th, 2006, 06:07 AM
Nice, nice... might use a variation on this, thanks for the idea! :thumb:

dclamp
Apr 4th, 2008, 07:15 PM
Thanks for this! i am going to use this function in a Authentication class i am going to use.

Will give credit

:wave: