Need help with password strength test script

Reply

Join Date: Aug 2005
Posts: 17
Reputation: StrikeFreedom is an unknown quantity at this point 
Solved Threads: 0
StrikeFreedom StrikeFreedom is offline Offline
Newbie Poster

Need help with password strength test script

 
0
  #1
Jun 20th, 2006
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:
?>
<form method="post" action="password_test.php">
<input name="password" type="password" id="password">
<input type="hidden" name="req" value="change_password">
<input type="submit" name="Submit" value="Submit">
</form>
<?
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
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Need help with password strength test script

 
0
  #2
Jun 20th, 2006
[PHP]<?
//usage
$strength_value = CheckPasswordStrength("$password");
echo $strength_value;

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

?>[/PHP]
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 17
Reputation: StrikeFreedom is an unknown quantity at this point 
Solved Threads: 0
StrikeFreedom StrikeFreedom is offline Offline
Newbie Poster

Re: Need help with password strength test script

 
0
  #3
Jun 21st, 2006
thanks!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC