Solved

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

Posted on 2008-06-11
2
175 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
Comment Utility
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
Comment Utility

<?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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

772 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

11 Experts available now in Live!

Get 1:1 Help Now