All TalkersCode Topics

Follow TalkersCode On Social Media

Password And Confirm Password Validation In PHP

Last Updated : Jan 1, 2023

Password And Confirm Password Validation In PHP

In this tutorial we will show you the solution of password and confirm password validation in PHP, in php, many times we have to create forms that are used for registration, login and other purposes.

In some forms, like registration we have to get password from user with validations.

Validations like password must be greater than 8 characters, it must contain one capital, one lower, one numeric and one special character also.

And there is one more validation that password and confirm password should be same.

So, let us see how to done the concept of password and confirm password in php.

Step By Step Guide On Password And Confirm Password Validation In PHP :-

Here, first we must have knowledge of how to apply validation of password. Validation like length of 8 characters, one capital and one lower alphabet, one numeric and one special character.

If you don’t know about these validation then you must visit to our previous article in which we show you how to apply validation on input type password.

Now, let us see the validation on password and confirm password with below example

if($pass != $cpass)
                    echo "<script> alert(' Please enter same password')</script>";
echo "<script> alert(' Entered password are same')</script>";
// another method
if ($_POST["pass"] === $_POST["cpass"]) {
   echo "<script> alert(' Entered passwords are same') </script>";
else {
   echo "<script> alert(' Please enter same passwords ') </script>";
  1. Here, as we see that we will show you two methods to check whether password and confirm password are same or not. Let us understand them one by one.
  2. In first of all, we have to save or say get our password and confirm password in variables. As you see we use $pass for password and $cpass for confirm password.
  3. We get the values or passwords in them from input type password and them compare them using if condition.
  4. If the passwords are same then a message with text entered passwords are same pop out otherwise another message having text please enter same passwords will appear.
  5. Now, let us understand our second method. This method is same like above method but have a minor difference that is our if condition in first method will execute if our passwords are not same whereas in second method our if condition executes statements if our both passwords are same.
  6. Here, we see that we did not save passwords in variables we directly use the name of inputs with the form method.
  7. Here, as you see that if both passwords are same then message having text Entered passwords are same will pop out otherwise please enter same password will appears.

Conclusion :-

At last in conclusion, here we can say that with the help of this article we are able to understand how to use validation in password and confirm password in php.

I hope this tutorial on password and confirm password validation in PHP helps you and the steps and method mentioned above are easy to follow and implement.

Latest Tutorials