I want to change the encryption of the user's password in the program, but the original one is that MD5, cannot decrypt it.

I want to change the encryption of user passwords in the program, but many user passwords have been stored in the database using the original MD5 encryption.

when login, the user enters the password and then MD5 encrypts it and then compares it with the data in the database. If the data is consistent, let the user log in.

if I change the encryption method, what should I do with the original account passwords?

because of MD5, I cannot decrypt the original encrypted password and encrypt it with a new encryption method, so old users will not be able to log in

Mar.06,2021

you can add a field to the database to save the encryption whether it is md5 or something else.
when logging in, judge the encryption algorithm
according to this field, and then notify the old user to change the password. The new password is the new encryption method. At the same time, the field that saves the encryption method is modified to a new encryption method


. The encryption type is MD5 by default (compatible with the current library). If you want to change the encryption method, new users come in and use the new one. After logging in successfully, the regular user changes the password encryption algorithm to the database


in order to be compatible with the original MD5 encryption method, you can pass the two encrypted passwords to the background when logging in, and the background takes two encrypted passwords to compare with the database password at the same time. If one passes, the login is successful. The original MD5 password continues to be stored in the original user database, while newly registered users and users who change their passwords are stored in a new encrypted way.


add a field, there is no need to force regular users to change their passwords

WHERE
(pwd=md5("123456") AND pwdType = "md5")
OR
(pwd=newFunc("123456") AND pwdType = "newMethod")
Menu