954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Need help with password strength test script

I'm trying to use the following script to test password strength:
[PHP]<?
switch($_REQUEST['req']){
case "change_password":

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");
echo $strength;
if($strength<3){
echo 'Weak Password';
}
break;

default:
?>


<?
break;
}
?>[/PHP]
I'm having problem with getting the value of the $strength variable after the function passed. When I try to echo it or use it in the if statement in the usage part the value of $strength is empty. But if I change the "return $strength;" to "echo $strength;" Then I can see the integer value of $strength there. Anyone knows how I can get the value of $strength outiside he function or has any alternatives? Thanks

StrikeFreedom
Newbie Poster
17 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

[PHP]<?
//usage
$strength_value = CheckPasswordStrength("$password");
echo $strength_value;

if($strength_value<3){
echo 'Weak Password';
}

?>[/PHP]

alpha_foobar
Junior Poster
182 posts since May 2005
Reputation Points: 20
Solved Threads: 5
 

thanks!

StrikeFreedom
Newbie Poster
17 posts since Aug 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You