In what form should we store our database passwords?

Source: Internet
Author: User
Tags asymmetric encryption
In actual applications, we usually store encrypted passwords in the database. Assume that our database has been illegally downloaded. If we used a non-symmetric encryption algorithm (MD5, RSA ...), Therefore, attackers have to pay a certain price to crack the password, because the shortest and the most stupid way to decrypt the ciphertext of the (break) asymmetric encryption algorithm is to crack the brute-force )! If we use a symmetric encryption algorithm to encrypt the password, once an attacker obtains the encryption key, he can decrypt all the passwords stored in the database. Therefore, the best way is to store the one-way hash of the password (combine the hash of this password with a salt value ): Public static string generatesalt (INT size)
{
Rngcryptoserviceprovider crypto = new rngcryptoserviceprovider ();
Byte [] buff = new byte [size];
Crypto. getbytes (buff );
Return convert. tobase64string (buff );
}
Public static string generatepwdhash (string PWD, string salt)
{
String saltpwd = string. Concat (PWD, salt );
String Password = formsauthentication. hashpasswordforstoringinconfigfile (saltpwd, "sha1 ");
Return password;
}

My problem is that the random salt value generated every time the user password is verified is different, and then the password is encrypted differently from that in the database. Isn't it a failure for every verification?

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.