PDA

View Full Version : Verify Password?



Dan
July 1st, 2009, 09:19
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:


<tr>
<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>
</tr>
<tr>


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?

david432111
July 1st, 2009, 11:26
http://www.plus2net.com/php_tutorial/php_signup.php
It explains how to make a nice php signup script that verifies passwords.
Just remember to use part II of the signup script if you want it to check passwords and stuff.

iBrightDev
July 1st, 2009, 16:54
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.

Dan
July 1st, 2009, 21:24
Cheers guys. Will look into these when I mentally wake up.

iBrightDev
July 2nd, 2009, 11:51
let us know if you need more help buddy. :D

Dan
July 3rd, 2009, 04:22
let us know if you need more help buddy. :D

Actually, there is something I would like done and will contact you on MSN regarding same. Few bucks in it for you. ;)

iBrightDev
July 4th, 2009, 12:59
righty-o Dan-a-rino.

Tree
July 8th, 2009, 22:29
If you wanted to make it more of an instant verification, there are plenty of JavaScript solutions available.

hip_hop_x
July 9th, 2009, 17:43
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

iBrightDev
July 15th, 2009, 10:39
If you wanted to make it more of an instant verification, there are plenty of JavaScript solutions available.

true, but, didnt want to confuse Dan with the ajax. :P

Corazu
July 15th, 2009, 16:01
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.