This post is part of the $100 Answers Series.
Context: We have a web application that requires users to login with their own password. Assume that the application is storing passwords in a custom database table--the solution isn't dependent on database functionality, but databases are common and I like to build my examples on something concrete. We'll also assume that the user's password is sent to the application over SSL/TLS and that the threat model for the application considers that acceptable.
- Require your passwords to be as long and as complex as your users will tolerate and still use efficiently
- Get the user's raw password
- Create a salt value by generating a 128-bit random number
- Concatenate the salt and raw password and feed them into SHA-256:
hashedPassword = SHA256( salt + rawPassword )
- Encode hashedPassword so that it is text and not binary
- Store hashedPassword in the password column in the database
- Store salt in the salt column in the database
- Require the user to change the password every two years
The rationale behind these steps is described in the rest of this post.