Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Secure Password Hashing

I need to store a hash of a single password in a .Net WinForms application.

What's the most secure way to do this?

In particular:

  • Salt, HMAC, or both?
  • How much salt?
  • How many iterations?
  • What encoding? (The password is plain ASCII)

I assume that the algorithm should be either SHA512 or HMACSHA512.

like image 770
SLaks Avatar asked Dec 03 '09 17:12

SLaks


2 Answers

Salt your hash with secure random salt of at least 128bits or longer, to avoid a rainbow attack and use BCrypt, PBKDF2 or scrypt. PBKDF2 comes with NIST approval.

To quote: Archive.org: http://chargen.matasano.com/chargen/2007/9/7/enough-with-the-rainbow-tables-what-you-need-to-know-about-s.html

The problem is that MD5 is fast. So are its modern competitors, like SHA1 and SHA256. Speed is a design goal of a modern secure hash, because hashes are a building block of almost every cryptosystem, and usually get demand-executed on a per-packet or per-message basis.

Speed is exactly what you don’t want in a password hash function.

Fast password validation functions are a problem, cause they can be attacked using brute force. With all the algorithms above you can control the "slowness"

like image 134
Sam Saffron Avatar answered Nov 13 '22 07:11

Sam Saffron


I can recommend BCrypt.net. Very easy to use and you can tune how long it will take to do the hashing, which is awesome!

// Pass a logRounds parameter to GenerateSalt to explicitly specify the
// amount of resources required to check the password. The work factor
// increases exponentially, so each increment is twice as much work. If
// omitted, a default of 10 is used.
string hashed = BCrypt.HashPassword(password, BCrypt.GenerateSalt(12));

// Check the password.
bool matches = BCrypt.CheckPassword(candidate, hashed);
like image 24
Svish Avatar answered Nov 13 '22 08:11

Svish