• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

Verify Password?


Hey folks,

I am setting up a script and in it there is a signup part where a person fills in a username and password. This is the password area:

      <td><span class="required">*</span>Password:</td>
      <td><input type="password" name="password" value="<?php echo $password; ?>" />
        <?php if ($error_password) { ?>
        <span class="required"><?php echo $error_password; ?></span>
        <?php } ?></td>

What I want to do is add an extra field where the person is required to verify their password. So, when both fields are filled in and the user clicks Submit, it would need to read the first password and compare it with the verified one and, when the verified field contains the wrong password it gives an error as such:

The passwords you have entered do not match!

Can anyone tell me how this is done?
just do a check on form submit Dan.

$errors = array();
$pass = $_POST['password'];
$cpass = $_POST['confirm_password'];
if (!empty($pass) && !empty($cpass)) {
  if ($pass != $cpass) {
    $errors[] = 'Your password and verification password dont match.';

if (!empty($errors)) {
  echo '<strong>Error:</strong><br/>The following error(s) occured.<br/><br/>';
  foreach ($errors as $msg) {
    echo "<em>- $msg</em><br/>\n";
  echo 'Please try again.';

hope that helps Dan.
If you wanted to make it more of an instant verification, there are plenty of JavaScript solutions available.
ajax, because javascript alone can be tricked very easy(since it's client side), btw if you'll check the password from a mysql database, use like this
$pass=mysql_real_escape_string($_POST['pass']); //for security
true, but, didnt want to confuse Dan with the ajax. :p

Keep in mind you still need the server side verification (for reasons posted above); also, if javascript is disabled then your login just won't work period.

Always good to grab all ends of the stick.