Use ASP. NET to encrypt passwords

Source: Internet
Author: User

When we create databases on our websites, it is necessary to protect user information security. Most users do not want to let others know their own information, and the network management does not want to lose the credibility of the website due to security issues. No matter who you are, security issues are very important.
To solve this problem, I will provide you with a simple and practical method, but the old one is password encryption. Here we use ASP. NET technology to encrypt passwords. To put it simply, encrypt the password provided by the user and compare it with the data stored in the system. If the password is the same, it passes verification.
In ASP, encryption objects are not provided. We can only use external objects for encryption. Now, the encryption solution is provided in ASP. NET. The namespace System. Web. Security contains the FormsAuthentication class. There is a method HashPasswordForStoringInConfigFile. This method can convert the characters provided by the user into garbled characters, store them, and even store them in cookies.
HashPasswordForStoringInConfigFile is easy to use. It supports "SHA1" and "MD5" encryption algorithms.
The following code demonstrates its usage in a simple way:

As you can see, this is easy to use. We can encapsulate this encryption program in a function to facilitate repeated use. The Code is as follows:

We can add a field to the database and use insert to store the encrypted password into the database as a string. When a user logs in, he/she can compare the password encryption result entered by the user with the correct result in the database. This method is used to verify the correctness of the password. Here, I will not write it down. The readers have to learn about the database.

Related Article

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.