I got a small program which take the password of user and checks its strength. That is if password consist of Uppercase alphabets, Lowercase alphabets, digits and symbols. Am not getting the expected result. for example if i put password as raj, i get
Digit 2
Uppercase 1 instead of Lowercase 3
Digit 2
Uppercase 1
Lowercase 0
Symbol 0
<?php
if($_POST['submit'] == "Check Password Strength")
{
$password = $_POST['password'];
$pwd = strlen($password);
$arrPwdLen = array();
// Inserting password in array
for($ik = 0; $ik < $pwd; $ik++)
{
array_push($arrPwdLen, $ik);
}
// Retrieving elements of array and checking to which category they belong:
// Uppercase alphabets, Lowercase alphabets, Digits or Special symbols
$LcaseAlpha = 0;
$UcaseAlpha = 0;
$Digit = 0;
$Symbol = 0;
for($i=0; $i<$pwd;$i++)
{
if(($arrPwdLen[$i] >= 'A') && ($arrPwdLen[$i] <= 'Z'))
{
$UcaseAlpha++; // Increment if element is uppercase alphabet
}
else if(($arrPwdLen[$i] >= 'a') && ($arrPwdLen[$i] <= 'z'))
{
$LcaseAlpha++; // Increment if element is lowercase alphabet
}
else if(($arrPwdLen[$i] >= " " ) && ($arrPwdLen[$i] <= "/") || ($arrPwdLen[$i] >= ":" ) && ($arrPwdLen[$i] <= "?") || ($arrPwdLen[$i] >= "[" ) && ($arrPwdLen[$i] <= "`") || ($arrPwdLen[$i] >= "{" ) && ($arrPwdLen[$i] <= "~"))
{
$Symbol++; // Increment if element is a special symbol
}
else
{
$Digit++; // Increment if element is digit
}
}
echo "Digit ".$Digit . "<br>";
echo "Uppercase ".$UcaseAlpha ."<br>";
echo "Lowercase ".$LcaseAlpha ."<br>";
echo "Symbol " . $Symbol;
}
?>