tags:

views:

72

answers:

3

Hi

I store the customers passwords in DB using encryption.

When the customer edits his personal data (including the password) the passwords are shown as *****

How can i understand that the use change his password so write to DB without encrypted again and again.

I mean that the value in password field is the encrypted value. If dont change the password must update with the same value (or not update at all) If user change password to 1234 I must encrypt the 1234 and write to DB the encrypted value

Thanks

+6  A: 

Don't send the md5 hashed string from the DB back. Set up three fields:

  • Old password
  • New password
  • New password again

Then check if the first field after md5 hashing is equal to the stored one in the DB. If it is, hash the second field and store it. (Only if the second and third is equal)

erenon
Thanks, i am going to ipmlement
ntan
works just fine
ntan
A: 

You should require entering both old and new password when user wants to change it.

That way, you can encode the old password, check if the encoded value is the same as in the database. If it is the same, then the you should update the password in db with encoded new password. If it is not the same (or old password is empty) you do not update.

This helps you to distinguish between password change and settings-only change. You also gain a some level of security, as if someone have captured the session of your user, he cannot change his password without also capturing is original password.

SWilk
A: 

A few points:

  • MD5 is a hashing algorithm, you will never be able to reverse the hash and that's the point.
  • Don't use MD5 as it has been cracked, use an SHA2+ Hash Algorithm (SHA256 for example)
  • Simply confirm the password with the "old password" by hashing the old password against the one in the database.
  • Another option is resetting the password, which will email their confirmed (hopefully) contact email with the new password.
  • If they're logged into the system already, you should not need to "confirm" the old password again.
  • Never send the hashed password back from the database, it is kind of defeating the purpose of what you are trying to accomplish.
Kyle Rozendo