Encrypt when you first get (and have verified) the password and store. When the user enters the password, encrypt it, retrieve the encrypted copy from the store and compare the encrypted versions. Never decrypt.
If you want to have a 'send me my password' link. Generate a new password, encrypt it and overwrite their old (encrypted) one in the store and send them the newly generated one.
You never store the unencrypted passwords, so even if the store is compromised, it doesn't open you up, because they only have the encrypted and you ask for the unencrypted.
By never needing to decrypt, you can use a one-way encryption, so noone can ever find the decryptions code. Of course the encryption code is probably around somewhere, but if the encryption is any good, they still have to do a brute force encrypt every word in the dictionary until they get a match for a password, before they can exploit it, and that ought to take a long time unless they get lucky.
Another precaution is to have a bunch encrypted passwords in the file derived from passwords that you wouldn't allow when your validating new passwords--things like 'password', 'secret', 'root' & 'admin'.
When people are logging in, don't validate, just encrypt it and see if it matches, then check the unencrypted against your 'no no' list. If you ever get a successful login using a word on your no no list, you know you've been Tango'd compromised. It would probably never happen, but for the effort involved, it's a simple sanity check.
In reply to Re: Encryption 101
by BrowserUk
in thread Encryption 101
by sulfericacid
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |