No. However, you can work around it, sort of:
- Add a new field to your database to hold a second password.
- Allow your users to log in as normal, with the MD5 system.
- After they have successfully authenticated, you know their password. So now just use
password_hash()
on it and store it in the new field.
- After some amount of time has passed, all active users will have their password encoded both ways.
- Remove the MD5 authentication and replace it with
password_verify()
.
- Any users that hadn't logged in during the transition period will simply have to reset their password.
Keep the transition period as short as reasonably possible. This will allow your most active users to transition transparently without having to leave your system exposed for too long.
Note -- ultimately, you should have them change their passwords, as the current ones should be considered weak.
Edit for clarification:
You don't necessarily need to make a new password column. Since the hashes generated by password_hash()
can be easily differentiated from those generated by md5()
, you can simply use a strlen()
check to determine which method to use. However, if you made your password field exactly the width of an MD5 hash string, then it's not going to be wide enough to hold the output of password_hash()
.