| | |
Need help with password strength test script
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Aug 2005
Posts: 17
Reputation:
Solved Threads: 0
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
[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
[PHP]<?
//usage
$strength_value = CheckPasswordStrength("$password");
echo $strength_value;
if($strength_value<3){
echo 'Weak Password';
}
?>[/PHP]
//usage
$strength_value = CheckPasswordStrength("$password");
echo $strength_value;
if($strength_value<3){
echo 'Weak Password';
}
?>[/PHP]
![]() |
Similar Threads
- i forgot my windowsXP password, please help me!!! (Windows NT / 2000 / XP)
- Test Script (VB.NET)
- how to test a software program on linux (C)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: Urgent (Issue in AS400. Software used Vision +)
- Next Thread: PHP URL Grabber
| Thread Tools | Search this Thread |
apache api array beginner binary body broken buttons cakephp checkbox class cms code cron curl database date date/time display dynamic ebooks echo email error file files folder form forms function functions global google href htaccess html image include insert ip javascript joomla limit link list login mail mediawiki menu mlm msqli_multi_query multiple mycodeisbad mysql number oop parameter paypal pdf php phpincludeissue problem query radio random recourse recursion regex remote script search seo server sessions sms source sp space speed sql static subdomain syntax system table tag tutorial update upload url validator variable vbulletin video web webdesign white wordpress xml youtube





