Simple implementation of user authentication with SHA1 or MD5

Source: Internet
Author: User
Tags interface md5 sha1

  (i). function

Use hash algorithm: SHA1 or MD5 to implement user account and password authentication.

Database storage Implementation principle is: User account directly stored in the database, password encrypted and then stored in the database. When a user logs on, the password is encrypted and then compared to the actual stored password in the database to determine whether the user is legitimate.

  (ii). Code and Implementation

1. Open namespaces:

Using System.Web.Security;

2. In the user registration interface, brief code:

Regist (Userid.text,formsauthentication.hashpasswordforstoringinconfigfile (Password.text, "MD5"));

Where: Userid.text means the user ID, that is, registered login account; Password.text represents the password for registration
The Regist implementation stores the account number and the encrypted password string in the database.

3. In the login interface, brief code:

Check (Userid.text,formsauthentication.hashpasswordforstoringinconfigfile (Password.text, "MD5"));

Wherein: Userid.text indicates the registered successful user ID, that is, the existing login account; Password.text indicates the password of the logged-on user

Regist the user entered the account and encrypted password and the database account password is matched.

The database is actually just storing the encrypted string. In addition to password encryption, you can also "prompt the question" "Prompt question answer" and other storage, the principle is the same.

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: and provide relevant evidence. A staff member will contact you within 5 working days.

Tags Index: