<p>What is the best way to handle user account management in a system, without having your employees who have access to a database, to have access to the accounts.</p>

<p>Examples:</p>

<ol>
<li><p>Storing username/password in the database.  This is a bad idea because anyone that has access to a database can see the username and password.  And hence use it.</p></li>
<li><p>Storing username/password hash.  This is a better method, but the account can be accessed by replacing the password hash in the database with the hash of another account that you know the auth info for.  Then after access is granted reverting it back in the database. </p></li>
</ol>

<p>How does windows/*nix handle this?</p>

[{'answer_id': 60758, 'author': 'mattruma', 'author_id': 1768, 'author_profile': 'https://Stackoverflow.com/users/1768', 'pm_score': 0, 'selected': False, 'text': '<p>You could store the <em>salt</em> for the hashed password in another table, of course each user would have their own salt.  You could then limit access to that table.</p>\n'}, {'answer_id': 60759, 'author': 'Christian Lescuyer', 'author_id': 341, 'author_profile': 'https://Stackoverflow.com/users/341', 'pm_score': 2, 'selected': False, 'text': '<ol>\n<li>A very bad idea indeed. If the database is compromised, all accounts are compromised.</li>\n<li>Good way to go. If your hash algorithm includes the username, replacing the password hash with another one will not work.</li>\n</ol>\n\n<p>Unix stores hashes in a a text file /etc/shadow, which is accessible only to privileged users. Passwords are encrypted with a salt.</p>\n'}, {'answer_id': 60767, 'author': 'Chris Upchurch', 'author_id': 2600, 'author_profile': 'https://Stackoverflow.com/users/2600', 'pm_score': 3, 'selected': False, 'text': "<blockquote>\n  <p>This is a better method, but the account can be accessed by replacing the password hash in the database with the hash of another account that you know the auth info for.</p>\n</blockquote>\n\n<p>There's really no way around this.  Anyone who as write access to the password file has complete control of the computer.  </p>\n"}, {'answer_id': 60787, 'author': 'arturh', 'author_id': 4186, 'author_profile': 'https://Stackoverflow.com/users/4186', 'pm_score': 2, 'selected': False, 'text': '<p>You could use openID and save no confidential user passwords at all. Who said it is for websites only?</p>\n'}, {'answer_id': 60864, 'author': 'Mr Shark', 'author_id': 6093, 'author_profile': 'https://Stackoverflow.com/users/6093', 'pm_score': 2, 'selected': False, 'text': '<p>I\'d go with 2 but use some salt. Some pseudocode:</p>\n\n<pre><code>SetPassword(user, password)\n    salt = RandomString()\n    hash = Hashfunction(salt+password)\n    StoreInDatabase(user, salt, hash)\n\nCheckPassword(user, password)\n    (salt, hash) = GetFromDatabase(user)\n    if Hashfunction(salt+password) == hash\n        return "Success"\n    else\n        return "Login Failed"\n</code></pre>\n\n<p>It is important to use a well known hash function (such as MD5 or SHA-1), implemented in a library. <strong>Don\'t roll your own or try implementing it from a book</strong> its just not worth the risk of getting it wrong.</p>\n\n<p>@Brian R. Bondy: The reason you use salt is to make dictionary attaks harder, the attacker can\'t hash a dictionary and try against all the passwords, instead she have to take the salt + the dictionary and hash it, which makes the storage requierments expode. If you have a dictionary of the 1000 most commaon passwords and hash them you need something like 16 kB but if you add two random letters you get 62*62*16 kB ≈ 62 Mb.</p>\n\n<p>Else you could use some kind of <a href="http://en.wikipedia.org/wiki/One-time_password" rel="nofollow noreferrer">One-time passwords</a> I have heard good things about OTPW but havent used it.</p>\n'}, {'answer_id': 60917, 'author': 'Jorge Córdoba', 'author_id': 2695, 'author_profile': 'https://Stackoverflow.com/users/2695', 'pm_score': 0, 'selected': False, 'text': '<p>The usual approach is to use option two with email:</p>\n\n<p>Store user name, password hash and email address into the database.</p>\n\n<p>Users can either input their password or reset it, in the latter case a random password is generated, a new hash is created for the user and the password is sent to him via email.</p>\n\n<p>Edit: If the database is compromised then you can only guarantee no sensible information can be accessed, you can no longer ensure the security of your application.</p>\n'}, {'answer_id': 60938, 'author': 'Graeme Perrow', 'author_id': 1821, 'author_profile': 'https://Stackoverflow.com/users/1821', 'pm_score': 0, 'selected': False, 'text': '<p>Hash the username and the password <em>together</em>. That way, if two users have the same password, the hashes will still be different.</p>\n'}, {'answer_id': 61204, 'author': 'Jarrod Dixon', 'author_id': 3, 'author_profile': 'https://Stackoverflow.com/users/3', 'pm_score': 2, 'selected': False, 'text': '<p>Jeff Atwood has some good posts concerning hashing, if you decide to go that route:</p>\n\n<ul>\n<li><a href="http://www.codinghorror.com/blog/archives/000949.html" rel="nofollow noreferrer">Rainbow Hash Cracking</a></li>\n<li><a href="http://www.codinghorror.com/blog/archives/000953.html" rel="nofollow noreferrer">You\'re Probably Storing Passwords Incorrectly</a></li>\n</ul>\n'}, {'answer_id': 74605, 'author': 'stormlash', 'author_id': 12657, 'author_profile': 'https://Stackoverflow.com/users/12657', 'pm_score': 3, 'selected': True, 'text': '<p>This was a common issue in UNIX many years ago, and was resolved by separating the user identity components (username, UID, shell, full name, etc.) from the authentication components (password hash, password hash salt).  The identity components can be globally readable (and in fact must be, if UIDs are to be mapped to usernames), but the authentication components <strong>must</strong> be kept inaccessible to users.  To authenticate a user, have a trusted system which will accept a username and password, and will return a simple result of "authenticated" or "not authenticated".  This system should be the only application with access to the authentication database, and should wait for a random amount of time (perhaps between 0.1 and 3 seconds) before replying to help avoid timing attacks.</p>\n'}, {'answer_id': 1176943, 'author': 'Mihai', 'author_id': 142647, 'author_profile': 'https://Stackoverflow.com/users/142647', 'pm_score': 0, 'selected': False, 'text': '<p>This is a bit of a non problem for a lot of applications because gaining access to the database is probably the most common goal of any attacker. So if they already have access to the database why would they still want to login to the application ? :) </p>\n'}, {'answer_id': 2795417, 'author': 'Kjetil Klaussen', 'author_id': 15599, 'author_profile': 'https://Stackoverflow.com/users/15599', 'pm_score': 0, 'selected': False, 'text': '<p>If the \'system\' is a public website <a href="https://rpxnow.com/" rel="nofollow noreferrer">RPX</a> can provide you with a login/user account services for the most common providers, like OpenId, Facebook, Google, etc. </p>\n\n<p>Now, given the way you formulate your question I guess the \'system\' you\'re talking about is more likely an internal windows/linux based enterprise app. Nevertheless; for those googling around for login/user account providers (like I did before a came across RPX), this could be a good fit :)</p>\n'}]
['https://Stackoverflow.com/questions/60757', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3153/']