title: How do I convert password hashing from MD5 to SHA?
body: <p>I've got an old application that has user passwords stored in the database with an MD5 hash. I'd like to replace this with something in the SHA-2 family.</p>
  
  <p>I've thought of two possible ways to accomplish this, but both seem rather clunky.</p>
  
  <p>1) Add a boolean "flag" field. The first time the user authenticates after this, replace the MD5 password hash with the SHA password hash, and set the flag. I can then check the flag to see whether the password hash has been converted.</p>
  
  <p>2) Add a second password field to store the SHA hash. The first time the user authenticates after this, hash the password with SHA and store it in the new field (probably delete their MD5 hash at the same time). Then I can check whether the SHA field has a value; this essentially becomes my flag.</p>
  
  <p>In either case, the MD5 authentication would have to remain in place for some time for any users who log in infrequently. And any users who are no longer active will never be switched to SHA.</p>
  
  <p>Is there a better way to do this?</p>