How to securely store user passwords ?, Secure storage of user passwords?

Source: Internet
Author: User

How to securely store user passwords ?, Secure storage of user passwords?

Original article link: click it

This article only captures a small part of the knowledge. Read the original article.

I. Basic Knowledge: Hashing with Salt)

We already know how fast a malicious attacker can use the query table and rainbow table to crack normal hash encryption. We have

We have learned that using random salt hashing can solve this problem. However, how can we change the value of salt?

Mixing in the password?

 

The salt value should use the encrypted Secure Pseudo-Random number generator (Cryptographically Secure Pseudo-Random)

Number Generator, CSPRNG. CSPRNG is very different from a common pseudo-random number generator,

For example, the rand () function in "C" language. As the name suggests, CSPRNG is designed for encryption security, which means it can

Random numbers that are highly random and completely unpredictable. We do not want the salt value to be predicted, so CSPRNG must be used.

The following table lists the CSPRNG methods of some mainstream programming platforms.

Platform CSPRNG
PHP Mcrypt_create_iv, openssl_random_pseudo _ bytes
Java Java. security. SecureRandom
Dot NET (C #, VB) System. Security. Cryptography. RNGCryptoServiceProvider
Ruby SecureRandom
Python OS. urandom
Perl Math: Random: Secure
C/C ++ (Windows API) CryptGenRandom
Any language on GNU/Linux or Unix Read from/dev/random or/dev/urandom

Each user's password must use a unique salt value. Each time a user creates an account or changes the password, the password should use a new random salt value.

Never reuse a salt value. This salt value should also be long enough so that there are enough salt values for hash encryption. An empirical rule is that salt

The value must be at least as long as the output of the hash function. The salt should be stored in the user account table together with the password hash.

Steps for storing the password:

  1. Use CSPRNG to generate a random salt value long enough.

  2. Mix the salt value into the password and use the standard password hash function for encryption, such as Argon2, bcrypt, scrypt, or PBKDF2.

  3. Store the salt value and the corresponding hash value in the user database.

Steps for password verification:

  1. The user's salt value and corresponding hash value are retrieved from the database.

  2. Mix the salt value with the password entered by the user and encrypt it using a common hash function.

  3. Compare the result of the previous step to check whether the hash value is the same as the hash value stored in the database. If they are the same, the password is correct. Otherwise, the password is incorrect.

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.