Hi All, I am trying to modify my code to calidate password criteria. I have the part checking the security code working fine, but I seem to be looping with the password validating. No matter what I type as password I get the error message. Can somone see what I am doing wrong here and suggest a fix. Its probably something simple but being new to this I cant see it.
<?php
require('edb.php');
$id=$_REQUEST['id'];
$SecurityCode=$_REQUEST['SecurityCode'];
$result=mysqli_query($conn, "SELECT * FROM `eusers` WHERE id = '".$_SESSION['uid']."'");
$test=mysqli_fetch_array($result);
if (!$result)
{
die("Error: Data not found..");
}
$FirstName=$test['FirstName'];
$LastName=$test['LastName'];
$State=$test['State'];
$Username=$test['Username'];
$Password=$test['Password'];
$Email=$test['Email'];
$Active=$test['Active'];
$SecurityCode=$test['SecurityCode'];
$AdviserCode=$test['AdviserCode'];
$UserType=$test['UserType'];
if(isset($_POST['Submit']))
{
$Password_save=sha1($_POST['Password']);
$Email_save=$_POST['Email'];
$Active_save=$_POST['Active'];
$SecurityCode_save=$_POST['SecurityCode'];
//check if the password and confirm password match
if($SecurityCode != $SecurityCode_save){
//if not display error message
echo "<center>The <b>Security Code</b> you supplied did not match the file! Your password has not been updated.</center>";} else {
// Validate password strength
$password = $Password_save;
$uppercase = preg_match('@[A-Z]@', $password);
$lowercase = preg_match('@[a-z]@', $password);
$number = preg_match('@[0-9]@', $password);
$specialChars = preg_match('@[^\w]@', $password);
if(!$uppercase || !$lowercase || !$number || !$specialChars || strlen($password) <8) {
echo 'Password should be at least 8 characters in length and should include at least one upper case letter, one number, and one special character.';
}else{
// END PASSWORD CHECK
mysqli_query($conn, "UPDATE `eusers` SET Password ='$Password_save' WHERE id ='".$_SESSION['uid']."' && SecurityCode ='$SecurityCode_save'")
or die(mysqli_error("Password change was not saved. You entered an incorrect Security Code"));
echo "Saved! Your password has been updated.";
}}}
?>