Solved

How to Compare new password to existing password to prevent using the same one.

Posted on 2008-06-11
2
176 Views
Last Modified: 2010-04-06
I have a page where users are redirected to change their password.  The logic I would like to add is to prevent them from re-using their existing password.  The existing password is stored in recordset  
rsLoginData and the field name is Password.  The field name on form1 for their new password is NewPassword.

Input appreciated.
0
Comment
Question by:drelinger
2 Comments
 
LVL 6

Accepted Solution

by:
ysfx earned 250 total points
ID: 21763697
You can have another field which requests the old password, thus requiring that the user entering the new password knows the old password. This way you can verify the old password with the new password immediately.

Otherwise, you will have to pull the information from  your database to validate the the password is not the same, or you can modify the update statement's criteria (ie where) by adding passwordcolumn <> 'newpassword'.
0
 
LVL 2

Assisted Solution

by:kszurek
kszurek earned 250 total points
ID: 21820881

<?PHP

if (strlen($_POST['old']) > 0 && strlen($_POST['new']) > 0)

{

	$old = trim($_POST['old']);

	$new = trim($_POST['new']);

	mysql_connect('localhost', 'user', 'password');

	mysql_select_db('expert');

	$result = mysql_query("SELECT password FROM rsLoginData WHERE user = 'username' LIMIT 1");

	$row = mysql_fetch_array($result, MYSQL_ASSOC);

	if ($row['password'] == $old)

	{

		if ($new == $_POST['new2'])

		{

			mysql_query("UPDATE rsLoginData SET password = '".mysql_real_escape_string($new)."' WHERE user = 'username' LIMIT 1");

			echo 'Password changed';

		} else echo 'Password mishmash';

	} else echo 'Old password is incorrect';
 

}

?>

<form method="post" action="a.php">

Old: <input type="password" name="old"><br />

New: <input type="password" name="new"><br />

Retype new: <input type="password" name="new2"><br />

<input type="submit" name="submit" value="Change!">

</form>

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now