Change the hash function in an existing database

I read password hashing a bit. I saw that SHA-256> MD5. This made me think about how an application can deal with the transition from one hash function to another. What happens if someone implements an application that hashes their passwords using MD5. Then they decide that SHA-256 is the way to go. But, of course, the password hashes stored in the database are in MD5.

What is the process of transferring data in a database from one hash function to another?

+5
source share
1 answer

It is impossible to β€œdecrypt” passwords (at least not in a general, efficient and reliable way), you can guess some passwords that attackers do, and you want to transfer from MD5 precisely because attackers may have some success with it). Thus, migration will spread over time: some passwords will be hashed with MD5, others with SHA-256. When the password is verified:

  • If the SHA-256 of this password is known, SHA-256 is used. This password has already been migrated.
  • Otherwise, MD5 is used to verify the password. If this matches, then the password is good, and since the application knew the password at that time, the application also hashes the password with SHA-256 and replaces the MD5 hash with the SHA-256 hash in the database.

, ; MD5, / , . MD5 SHA-256, , (16 MD5, 32 SHA-256). .

, - - , MD5 SHA-256, . -, , , . , , "" ( , ) - (.. , , ) -). . . : , bcrypt, SHA-256 (. , security.stackexchange).

+5

All Articles