(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.