Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirm Password?

Tags:

php

New to all this so forgive my ignorance. I am trying to figure out how to add a "confirm your password" field to my form. Using PHP and mySQL. Is this entered in the html form code, and how can you set it to auto check that the password and confirm password fields match.

like image 912
bgadoci Avatar asked Oct 26 '09 02:10

bgadoci


People also ask

What is a confirm password?

If users mistype their password, they won't recognize it. The confirm password catches typos by prompting users to type their password twice.

Why Confirm password is important?

The idea behind the confirm password field was that some users mistyped their password when they signed up and were locked out of their account when they tried to log back in. So to fix this, designers added a second password field to double check the user typed what they meant to type.


2 Answers

Just get both the password and confirm password fields in the form submit PHP and test for equality:

if ($_POST["password"] === $_POST["confirm_password"]) {
   // success!
}
else {
   // failed :(
}

where password and confirm_password are the IDs of the HTML text inputs for the passwords.

like image 94
Kaleb Brasee Avatar answered Sep 17 '22 12:09

Kaleb Brasee


What you're trying to do is form validation. It's a good idea do validate on the client side (using javascript) so you have a faster response for your user on the interface, and on your server side (since your user can have javascript disabled - and because you should never blindly trust in user input. Read Should you do validation on your server side for some more information about this subject).

You just need to compare the two posted values. If correct, insert in database. If not, dont do anything and returns a message to the user saying that the password is incorrect.

I can't give more details since you didn't provide enough or detailed information of your php environment (frameworks used, libs used, etc).

like image 43
GmonC Avatar answered Sep 20 '22 12:09

GmonC