Encrypt passwords using ASP.net

Source: Internet
Author: User
Asp.net| encryption when we set up a database on the website, it is necessary to protect the user's information security. Most users do not want to let others know their own information, while network management also do not think because of security issues and loss of credibility of the site. Security issues are very important to anyone.

To solve this problem, I provide you with a simple and practical, but the old-fashioned way, is password encryption. Here we use ASP.net technology to encrypt passwords. Simply put, the password that is supplied by the user is encrypted, then it is compared to the data stored in the system and, if the same, is validated.

In ASP, no encrypted objects are provided, we can only use external objects for encryption. Now it's okay to provide a solution for encryption in asp.net. A class FormsAuthentication is included in the namespace System.Web.Security, which has a method hashpasswordforstoringinconfigfile. This method can turn user-supplied characters into garbled, then store them, and can even be stored in cookies.

The HashPasswordForStoringInConfigFile method is simple to use, and it supports the "SHA1" and "MD5" cryptographic algorithms.

The following code is a simple demonstration of its usage:

  

As you can see, this is simple and easy to use. We can encapsulate this encryption program in a function that is easy to reuse. The code is as follows:

  

We can add a field to the database and use Insert to store the encrypted password as a string in the database. When the user log in, it can be the user input password encryption results and the correct results in the database comparison, through this method to verify the correctness of the password. Here, I will not write down, about the knowledge of the database and readers themselves to learn.


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.