Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to hash a password and authenticate a user client-side?

I often make small websites and use the built in ASP.NET membership functionality in a SQL Server database, using the default "hashing" password storage method.

I'm wondering if there's a way to authenticate a user by hashing his password on the client and not sending it in clear text over the wire without using SSL.

I realize that this would only be applicable for users with Javascript enabled.

Or... possibly, this would be a great built-in capability for Silverlight (is this in the Silverlight roadmap?)


EDIT: I'm also looking for "degrees of security." Meaning, if there is a method that has some advantages over simply sending plaintext password, I'd like to know what they are and why.

I know there are lots of people who do small sites with logins (such as a family website or volunteering to make a site for a local cooking club) and don't see the need for purchasing SSL certificates.

like image 391
Feckmore Avatar asked Jul 06 '09 16:07

Feckmore


People also ask

Can hash be used for authentication?

Hashing is a cryptographic process that can be used to validate the authenticity and integrity of various types of input. It is widely used in authentication systems to avoid storing plaintext passwords in databases, but is also used to validate files, documents and other types of data.

Do you hash password on frontend or backend?

And the hash step is always done on the backend, since doing it on client-side would allow an attacker which got access to your hashes a method to login on every account. Save this answer.

How are hash functions used to authenticate passwords?

Hashing turns your password (or any other piece of data) into a short string of letters and/or numbers using an encryption algorithm. If a website is hacked, cyber criminals don't get access to your password. Instead, they just get access to the encrypted “hash” created by your password.

What is client hash?

Client Hash is a lightweight library implementing the most extended cryptographic hash function algorithms in pure JavaScript (ES5 compliant). The goal is to provide a dependency-free, fast and reliable solution for hash algorithms for client-side actions.


2 Answers

This is possible. This is actually what Kerberos authentication does, only with a little bit of added spice. To ensure that your authentication mechanism is secure, you need the following:

  1. A common hashing algorithm on both the client and server.
  2. A one-time salt value generated on the server and shared with the client.
  3. The original password stored in a database.

To securely authenticate a user via hash code, so you avoid sending the actual password across the wire, first generate a random, single-use salt value on the server. Send this salt value to the client, and generate a hash code from the salted version of the password the user has input. Send the resulting hash code to the server, and compare it with a hash code generated from the salted version of the stored password. If the comparison fails, discard the salt, regenerate a new salt value, and repeat the process.

The reason for the single-use salt is to prevent anyone listening to the conversation from capturing the hash code of the users password, which, when you use hash code comparison, is just as good as having the password itself.

Note that you need to keep the original password around, you can't hash it once on the server and save the hash in the database. If you need to ensure that the passwords stored in your database are also secure, then you will need to encrypt them before storing them. I believe that ASP.NET membership providers do allow you to store passwords encrypted, however, if you really wish to have a secure authentication mechanism that is difficult for a hacker to crack, then I would recommend handling password storage and retrieval entirely on your own.

Finally, I should note, that such a complex password transfer mechanism should be largely unnecessary if you use SSL to encrypt your connection during authentication.

References (for those who have never heard of Kerberos or SRP):

http://en.wikipedia.org/wiki/Kerberos_(protocol) http://en.wikipedia.org/wiki/Secure_remote_password_protocol

like image 193
jrista Avatar answered Nov 15 '22 01:11

jrista


This is a bad idea, security wise. If you send a non-ssl form that contains the hashed password, then anyone capturing traffic has all they need to login. Your javascript has to result in something that indicates success (a redirect, token passed to the server, etc). Whatever it is, the listener now can recreate that without proper authentication.

SSL was built for a reason, by people who tried a lot of other web authentication schemes. It is far safer and cheaper to get a cert than to try write your own safe authentication scheme that works without encryption.

Added for clarity:

Client side hashing alone is not safe. Say I have a form with the following inputs

<form action="signin.whatever" method="post">
<input type="text" id="txtUser">
<input type="text" id="txtPass">
<input type="hidden" id="hiddenHash">
<input type="submit" onclick="hashAndSubmit()">
</form>

where hashAndSubmit() hashes the password and puts it in hiddenHash, and blanks out the password field. If I sniff your submission and see the following fields:

txtUser:joeuser
txtPass:
hiddenHash:xxx345yz   // hash result

that's all I need as an attacker. I build a form with your user and hash value and I'm all set. The password is not necessary for a replay attack.

To get around this, you have to look at one-time salt values, or other schemes. All of which introduce more cost(don't forget developer time) and risk than SSL. Before you do something like this, ask one question...

Do I trust myself more than years and years of public testing of the SSL encryption?

like image 26
Tim Hoolihan Avatar answered Nov 15 '22 00:11

Tim Hoolihan