Use the DataSet section to achieve Website login

Source: Internet
Author: User

This is my first blog post, there is a little excitement, I do not think one day I can write a little experience for everyone to serve. Please forgive me if there is no clear expression.

First of all, I must have completed the registration and put the personal information into the database.

Second, the individual objects in this section are stored in some documents and need to refer to 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; ///Back to Scripthelper object (ScriptHelper.cs is the CS file you wrote)
Using System.Data; //Use a dataset behind

Namespace WebApplication
{
public partial class Login:System.Web.UI.Page
{
protected void Page_Load (object sender, EventArgs e)
{

}
// <summary>
Login button
</summary>
<param name= "Sender" ></param>
<param name= "E" ></param>

protected void Btnlogin_click (object sender, EventArgs e)
{
//user Table Sys_user column personstatus is "normal" to log in or prompt the account status to Personstatus content
Column Personcode user name password to password
The password stored in the database is the encrypted string. Ext_decryptstring (); for decrypting ext_encryptstring (); for encryption

String userName = TxtUserName.Text.Trim (); //. Trim () is the null character before and after the string is removed
String PassWord = TxtPwd.Text.Trim ();

//. Ext_isnullorempty () is a function written in another file that determines whether a string is a null character (also available username== "")
if (Username.ext_isnullorempty ())
{
Scripthelper.showalertscript ("Please enter user name!") "); //pop-up form tips
Return
}

if (Password.ext_isnullorempty ())
{
Scripthelper.showalertscript ("Please enter your password!") ");
Return
}

In the Sys_user table, filter out the number of data that the user named username, if 0 means there is no user, and 1 for that.

DataSet ds = Sqlhelper.getdata ("SELECT count (*) from Sys_user where personcode= '" + username+ "'");
if (ds. Tables[0]. Rows[0][0]. ToString ()! = "1")
{
Scripthelper.showalertscript ("User name does not exist! ");
Return
}

The Personstatus value of the user named username is filtered in the Sys_user table.

DataSet dsstatus = Sqlhelper.getdata ("Select Personstatus from Sys_user where personcode= '" + userName + "'");

Remove the value of the column named Personstatus in the first row of the first table in the Dsstatus (small database) ([0])
String personstatus = Dsstatus.tables[0]. rows[0]["Personstatus"]. ToString ();
if (personstatus! = "normal")
{
Scripthelper.showalertscript ("User status is incorrect:" + personstatus);
Return
}

Note that the password is encrypted, and the null character is not empty after it is encrypted. The password in the database is the encrypted character, and the actual comparison needs to be encrypted with the actual input character and compared with the database.

//Judge password method oneString 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 ("The password is incorrect! ");
Return
//}//Password method twoString 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 login successfully jump to homepage
Response.Redirect ("index.aspx");
}
}
}

Use the DataSet section to achieve Website login

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.