skiwi
skiwi

Reputation: 69349

Password security

Currently I am using a particular scheme for securing passwords, and I think I have some points for improvement. The implementation is in Java, so I prefer to use SHA-2 512 as encryption form.

Currently I have a client-server model, so these things can happen:

I have these questions:

Regards.

Upvotes: 1

Views: 247

Answers (1)

Steve
Steve

Reputation: 7271

TLDR: You need to send the password using an encrypted channel, such as TLS. Consider using bcrypt for password hashing.

SHA-2 512 is not an encryption algortihm, it is a message digest algorithm. An encryption algorithm requires a key and a message to encrypt. It produces ciphertext. The important thing is that an encryption algorithm has a decryption algorithm.

ciphertext = E(key, plaintext);
plaintext = D(key, ciphertext);

A message digest takes a piece of plaintext and produces a message digest. There is no corresponding reverse mechanism to take a message digest and retrieve the original message. There is also no secret key.

digest = hash(plaintext);

If an attacker is able to access a database with hashes, the attacker can retrieve the original password by brute forcing, trying lots of guesses with the hash algorithm.

digest1 = hash(guess1);
digest2 = hash(guess2);    //repeat with lots of guesses

Firstly, sending a hash over a network is not secure. It needs to be sent through some secure communications mechanism such as SSL. If an attacker can intercept the hash over the communications they may be able to work out the orignal password.

A hash collision is not the same as brute forcing the password. A hash collision is caused when two different messages produce the same message digest.

digest1 = hash(plaintext1);
digest2 = hash(plaintext2);
if ( ( plaintext1 != plaintext2 ) && ( digest1 == digest2 ) )  
    // hash collision

SHA-512 does not have iterations designed to prevent brute-forcing. The SHA set of algorithms are designed to be efficient. The reason for adding iterations when hashing passwords is to increase the time it takes to brute force a password. The idea being the cost to perform a legitimate login attempt and perform 100 iterations is tiny compared to an attacker who has millions of passwords, each of which requires 100 iterations. Adding more iterations helps reduce the impact of improved processor speeds (which would help an attacker try more iterations quicker).

You should make the number of iterations a configurable limit that is stored against each user. So you store the password hash, salt and iteration count for each user. This means that in the future you can increase the number of iterations to take into account increased hardware power.

Sending the SHA-2 512 in plaintext is not secure. You should send it within an encrypted channel, such as SSL.

Having said all that, SHA-2 is not designed to be a password hashing algorithm. It is designed for message validation and is to be efficient. Consider using a purpose built password hashing algorithm. One example is bcrypt. It is designed to be computationally difficult and has salt and iterations built in.

Upvotes: 5

Related Questions