Question

I have a problem in registration form in my website whatever i type in confirm password it convert it to one (I Knew it when I echo the password and Confirm Password) and although the two values are different, it always gives me true when I compare between the password and the confirmation

here is the HTML:

<span><p>Password:</p>
<input type="password" size="25" name="password" placeholder="Enter Your Password"     style="margin-bottom:2ex;"  />
<font color="red">*</font>
<font color="grey">At least 8  characters.</font></span>
<span><p>Confirm Password:</p>
<input type="password" size="25" name="confirm_password" placeholder="Confirm Your Password" style="margin-bottom:2ex;"  />
<font color="red">*</font></span>

and here is my PHP Code

if (isset($_POST['signup'])) {
  if ($_POST['password'] != NULL && $_POST['confirm_password'] = !NULL) {
  $password = $_POST['password'];
  $confirm_password = $_POST['confirm_password'];

  if ($password != $confirm_password) {
  print ("<p><b><font color='red'>Provided passwords do not match</font></b></p>");
  } 

  else {
  $password = md5($password);
  //do the rest of code
  }
 }
}

UPDATE

There are some hidden part of the code, the submit button name is signup, and i checked that the values of the fields are not null another thing converting to one means that the value is always = 1

Was it helpful?

Solution

This line:

if ($_POST['password'] != NULL && $_POST['confirm_password'] = !NULL) {

this = !NULL needs to be != NULL

if ($_POST['password'] != NULL && $_POST['confirm_password'] != NULL) {

Password storage:

Consider using CRYPT_BLOWFISH or PHP 5.5's password_hash() function. For PHP < 5.5 use the password_hash() compatibility pack.


  • MD5 is considered too fast and is outdated.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top