Recommendations for encrypted password and email retrieval
I just finished encrypting the passwords in my database using a salted sha1. Naturally I'll need to implement a forgot password link ( email as well ). I have make shift 开发者_如何转开发versions of those right now that are no good.
I am assuming due to the style of encryption, that I will need to prompt the user to reset their password.
I am just looking for the most secure way to do this. Any suggestions, or links to resources and tutorials, as well as what kinda of method I should use would be greatly appreciated.
thanks and good day.
Just to be clear, sha1
, salted or cheesy onion flavour, is not encryption, it is called hashing. It's a one way function with unique output for unique. The idea of using a salted hash for passwords in your database is twofold:
- The hash is a one way function, so nobody with access to the database can actually determine what those passwords are. Very good practise.
- The salted part, assuming you're hashing the username+password+some junk, means that each username + password combination should be a unique hash. It makes dictionary attacks / shortcuts via precomputed hashes difficult, because most people don't have a dictionary of
ninefingers:stackoverflow!!:{insertcommonwordhere}
lying around. It doesn't stop them generating it, just makes it more inconvenient.
Now we've cleared that up, yes, if the user forgets their password, you can't email it to them because you can't reverse the hash. By design.
Instead, what you're looking to do is allow the user to securely reset their password. The simplest form of this is that, if the user enters their email address, you email them a link to your site including in its parameters a unique, use-once token valid for a short time window.
Other options? Generate them a password and email them that. The Uk Gov't Gateway here in the UK does something quite interesting: the web-page contains half the password, the email the other half. You need both to then log in again.
Now, the million-dollar question: is it secure? No. Nothing's secure. There is no 100% security. Ever. This particular method of storing passwords adds security because:
- DBAs can't easily abuse their access to the user table;
- Malicious requests that somehow
select * from table users;
can't easily read those passwords either.
But as soon as you rely on being able to email the user as a method of secure communication, you rely on:
- Their email account being secure;
- That their email is not being monitored.
The question then becomes - how secure do you really need to be? Implementing the email-out-a-reset-link solution will work for most cases because they're not high-value enough targets, really.
精彩评论