Mr_Person has asked for the wisdom of the Perl Monks concerning the following question:
I'm writing a web app where users' passwords will be stored in a database. I know that I should use a hash function with a salt for storing the passwords, but most of the suggestions I've seen involved making your own system. Are there any modules out there that do it for you? I found Crypt::PasswdMD5, but it seems to go throught a lot of extra trouble just to be compatible with an existing implimentation, plus I know that MD5 is sorta on the way out.
If I do need to write my own, any suggestions for how to go about it?
Thanks!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passwords, hashes, and salt
by waswas-fng (Curate) on Jun 24, 2005 at 18:37 UTC | |
The reason you "salt" the plain-text is so that if you have 30,000 users in the password database and you want to check to see if any use the password "greatwork" you have to digest it against up to 30,000 salts instead of just just digesting it once and moving on to the next word in the attack. Adding more than 2 random chars to a salt potentially adds more difficulty as you have more users in the database, as there would be less salt overlap. I hope this makes sense... -Waswas | [reply] [d/l] |
by Mr_Person (Hermit) on Jun 24, 2005 at 19:15 UTC | |
| [reply] |
|
Re: Passwords, hashes, and salt
by Zaxo (Archbishop) on Jun 24, 2005 at 18:33 UTC | |
Crypt::PasswdMD5 is, in practice, easy to use. The salt is prefixed to the the returned password hash, so you don't need to use a constant one. Just extract that substring from the stored hash and use it as salt for the offered password, then compare strings. When you first store a password hash, any random salt will do. The randommer, the better. The purpose of salt is to make wordlist dictionarys impractically large. After Compline, | [reply] |
|
Re: Passwords, hashes, and salt
by dynamo (Chaplain) on Jun 24, 2005 at 18:22 UTC | |
It's fairly straightforward how to implement this yourself - check the hashed password against the database for an auth request, hash and store the password when creating a user or changing a password. What else did you need to know? | [reply] |
by ikegami (Patriarch) on Jun 24, 2005 at 18:34 UTC | |
Adding salt does two things: 1) It makes it harder to brute force the password list. 2) If person A knows his password hashes to the same value as person B's -- some websites stupidly publish users that had the same password hash -- person A could login as person B using their own password without even knowing person B's password. Adding salt would create different hashes (even for the same password), eliminating this problem. usually based on some input from the user record or the password itself Salts are usually random. Ideally, each user has a different salt. They must definitely NOT be based on the password since the salt must be known. Basing it on the password would leak info about the password. Crypt::PasswdMD5 creates a salt for you if you don't specify one, according to the documentation. | [reply] |
by Anonymous Monk on Jun 24, 2005 at 18:31 UTC | |
I'm not sure how salt really adds anything useful to the pictureSalt makes your passwords less vulnerable to dictionary attacks. | [reply] |
|
Re: Passwords, hashes, and salt
by TedPride (Priest) on Jun 24, 2005 at 19:26 UTC | |
Personally though, I'd work more on making sure the database is secure from prying eyes, rather than hashing stored passwords. Storing passwords as irreversable hashes means there's no way to retrieve the password if the password is forgotten, meaning in turn that you need a secondary verification system - which is always less secure and usually fairly easy to social engineer. If you ARE going to make passwords irreversable, make them short (no more than 3-4 alphanumeric characters), with lock-out of IP / user on failure to log in 3 times in a row. A short password is much easier to remember, and pretty much eliminates the need for a secondary verification system. The weakest link is almost never site security, but rather human laziness and inability to remember things. | [reply] |
by waswas-fng (Curate) on Jun 24, 2005 at 20:24 UTC | |
One (of many) reason almost all secure apps use trap door encryption for passwords is that it is not reversible. That is KEY. One such attack that this defeats is your system administrator, which has access to all of your accounts and passwords, knowing the passwords when he gets laid off next week. To reset or change your password other sources of information are used for verification such as your email address with a click back, or all the way up to physical request in person with multiple forms of ID. Having plain text stores of passwords totally blows the user:pass concept of proving identity. Just think of this: if your server is compromised, and you can determine the break in exploit and time table, with plain text passwords in your database you cant roll back to the pre-exploit time and patch the issue. you have to have everyone on the system reset their password. -Waswas | [reply] |
|
Re: Passwords, hashes, and salt
by Anonymous Monk on Jun 24, 2005 at 18:24 UTC | |
...is a lot of extra trouble, especially since rolling your own would seem to be a lot of busy work for very little gain. | [reply] [d/l] |
by waswas-fng (Curate) on Jun 24, 2005 at 18:40 UTC | |
-Waswas | [reply] |
by Mr_Person (Hermit) on Jun 24, 2005 at 19:07 UTC | |
| [reply] |
|
Re: Passwords, hashes, and salt
by dynamo (Chaplain) on Jun 24, 2005 at 18:34 UTC | |
| [reply] |
by waswas-fng (Curate) on Jun 24, 2005 at 19:08 UTC | |
look here (offsite:rub.de) for an article that explains the current publicly announced state of things. I as this gets more eyes on it, it will get even worse. MD5 digests should be considered almost as insecure as mad XOR magic. =) Update: just wanted to add that SHA-1 has some of the same weaknesses as MD5, but as of yet they have not been able to break it like MD5. If you are really worried you can goto something like Digest::SHA256 for a digest, but it may not be worth it yet. -Waswas | [reply] |
by Mr_Person (Hermit) on Jun 24, 2005 at 19:08 UTC | |
| [reply] |
|
Re: Passwords, hashes, and salt
by TedPride (Priest) on Jun 25, 2005 at 06:57 UTC | |
Incidently, I fail to see how any security method is going to save you if the person with root gets pissed off. He can social engineer people; he can redirect himself a copy of their user names and passwords on login; he can scan data streams and memory; etc. All he needs is a few logins to make your entire database unsafe, unless you know exactly which ones he has. Face it, you're screwed. The only thing you can prevent is him knowing everyone's password in one easy step, but why would that matter when he has root? He controls everything. EDIT: I suppose if you know who logged in when and also when it was he inserted the redirect, you could identify which users he had the login info for and reset just their passwords. To prevent this, he'd also have to edit the logs before every site backup, which I admit would add a level of complexity to things. Still, anyone with half a brain would most likely have no trouble doing this. | [reply] |
by waswas-fng (Curate) on Jun 27, 2005 at 15:09 UTC | |
You Said: Just merge the user name and password and salt in such a way that the hash is unique for every user name and password pair, and completely unguessable through dictionary attack or brute force Which is one of the things in your post that made me realize you did not have your eye on the prize. Salt guess-ability is not a factor, they do their job while being totally known and visible. in fact you could just inc 01 .. N for salt on each new username and be done --all that matters really is that they are different per password. All your suggestion does in this post is to try to obfu salt into the password/hash -- this buys you nothing. Later on you say: Personally though, I'd work more on making sure the database is secure from prying eyes, rather than hashing stored passwords. Storing passwords as irreversible hashes means there's no way to retrieve the password if the password is forgotten, meaning in turn that you need a secondary verification system - which is always less secure and usually fairly easy to social engineer. If you ARE going to make passwords irreversible, make them short (no more than 3-4 alphanumeric characters), with lock-out of IP / user on failure to log in 3 times in a row. A short password is much easier to remember, and pretty much eliminates the need for a secondary verification system. which I see so many issues with I cant really spend the time going into it in detail. All I will say is that the second level password reset systems are as secure as they are designed to be -- while your posting account on perlmonks may be easy to get reset, your cert and pass at a DOD installation may require physical request with ID. It is all in the design and risk assessment of the particular site -- You have to remember at the end of the day user:pass systems are there to verify identity. If anyone on your system can freely grab user:pass info -- they can't be used to verify identity. -Waswas | [reply] |