Use some DataSet functions to log on to the website, and use dataset to log on to the website.

Source: Internet
Author: User

Use some DataSet functions to log on to the website, and use dataset to log on to the website.

First, I have to complete registration and store my personal information in the database.

Secondly, some objects in this section are stored in some documents and need to reference namespaces.

Using System; using System. collections. generic; using System. linq; using System. web; using System. web. UI; using System. web. UI. webControls; using ZG. common; // The ScriptHelper object (ScriptHelper. cs is a self-compiled cs file) using System. data; // datasetnamespace WebApplication {public partial class Login: System. web. UI. page {protected void Page_Load (object sender, EventArgs e) {}/// <summary> // logon button /// </summary> // <p Aram name = "sender"> </param> // <param name = "e"> </param> protected void btnLogin_Click (object sender, EventArgs e) {// you can log on only when the PersonStatus column in The Sys_User table is "normal". Otherwise, the system prompts that the account status is the content in the PersonStatus. // The PersonCode column is the username and PassWord. // The PassWord saved in the database is the encrypted string. ext_DecryptString (); to decrypt Ext_EncryptString (); to encrypt string userName = txtUserName. text. trim ();//. trim () is to remove the null character string passWord = txtPwd before and after the string. text. trim ();//. ext_IsNullOrE Mpty () is a function written in another file. It is used to determine whether the string is a null character (also known as userName = "") if (userName. ext_IsNullOrEmpty () {ScriptHelper. showAlertScript ("Enter the user name! "); // The prompt" return;} if (passWord. Ext_IsNullOrEmpty () {ScriptHelper. ShowAlertScript ("enter the passWord! "); Return;} // In the Sys_User table, the number of data records with userName is filtered out. If the value is 0, this user is not found, and 1 indicates yes. DataSet ds = SqlHelper. getData ("select count (*) from Sys_User where PersonCode = '" + userName + "'"); if (ds. tables [0]. rows [0] [0]. toString ()! = "1") {ScriptHelper. ShowAlertScript ("the user name does not exist! "); Return;} // filter the PersonStatus value of userName in the Sys_User table. DataSet dsStatus = SqlHelper. getData ("select PersonStatus from Sys_User where PersonCode = '" + userName + "'"); // retrieve the dsStatus (small database) ([0]) the value of the column PersonStatus in the first row of the first table is string personStatus = dsStatus. tables [0]. rows [0] ["PersonStatus"]. toString (); if (personStatus! = "Normal") {ScriptHelper. showAlertScript ("incorrect user status:" + personStatus); return;} // note the encryption of passwords. Empty characters are not empty characters After encryption. The password in the database is an encrypted character, in actual comparison, the encrypted characters that need to be entered must be used to compare with those in the database // determine the password method 1 // string SQL = "select * from Sys_User where PersonCode = '{0} 'and Password =' {1 }'"; // DataSet dsUser = SqlHelper. getData (string. format (SQL, userName, passWord. ext_EncryptString (); // if (dsUser. tables [0]. rows. count! = 1) // {// ScriptHelper. ShowAlertScript ("Incorrect password! "); // Return; // determine password method 2 string SQL =" select * from Sys_User where PersonCode = '{0}' "; DataSet dsUser = SqlHelper. getData (string. format (SQL, userName); if (dsUser. tables [0]. rows [0] ["PassWord"]. toString ()! = PassWord. Ext_EncryptString () {ScriptHelper. ShowAlertScript ("the passWord is incorrect! "); Return;} Session [" UserName "] = dsUser. tables [0]. rows [0] ["PersonCode"]. toString (); Session ["LoginUser"] = dsUser. tables [0]. rows [0] ["PersonName"]. toString (); Session ["UserID"] = dsUser. tables [0]. rows [0] ["ItemID"]. toString (); // If the logon succeeds, the Response is displayed on the homepage. redirect ("index. aspx ");}}}

The above section describes how to use the DataSet function to log on to the website. I hope it will be helpful to you. If you have any questions, please leave a message. The editor will reply to you in time!

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.