Confirm the password?

New to all this will forgive my ignorance. I am trying to figure out how to add a "confirm password" field to my form. Using PHP and mySQL. This is entered in the html form code, and how you can configure it to automatically check the correspondence of password fields and password confirmation.

+5
source share
5 answers

Just enter the password and confirm the password in the submit PHP form and check the equality:

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

where passwordand confirm_passwordare the HTML text input identifiers for passwords.

+16
source

, , - . ( javascript), ( javascript - , trust. ).

. , . , , .

, php ( , ..).

+4

JavaScript,

    <html><title></title><head>
<script>
        function validate(){

    if(!document.getElementById("password").value==document.getElementById("confirm_password").value)alert("Passwords do no match");
    return document.getElementById("password").value==document.getElementById("confirm_password").value;
   return false;
    }
    </script>
</head>
<body>
    <form onSubmit="return validate()" action="nextPage.php">
    Password: <input type="text" id="password" name="password" /><br/>
    Reenter Password: <input type="text" id="confirm_password" name="confirm_password" />
    <input type="submit" value="submit"/>
    </form>
</body>
</html>

, JavaScript Enabled,

if($_GET['password']==$_GET['confirm_password'])

$_POST $_GET POST

+2

, submit.

 <html>
   <title></title>
    <head>
    <script>
        function validate(){

            var a = document.getElementById("password").value;
            var b = document.getElementById("confirm_password").value;
            if (a!=b) {
               alert("Passwords do no match");
               return false;
            }
        }
     </script>
    </head>
    <body>
        <form onSubmit="return validate();" ">
        Password: <input type="text" id="password" name="password" /><br/>
        Re-enter Password: <input type="text" id="confirm_password" name="confirm_password" />
        <input type="submit" value="submit"/>
        </form>
    </body>
 </html>
+2

- ? , , , , $confirmPassword == $passWord. SQL.

+1

All Articles