Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use some functions of DataSet to realize website login

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you how to use some of the functions of DataSet to log in to the website. I hope you will get something after reading this article. Let's discuss it together.

First of all, I must complete the registration before and store my personal information in the database.

Second, individual objects in this section are stored in some documents and need to refer to namespaces.

The ScriptHelper object is used after using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using ZG.Common;// (ScriptHelper.cs is a cs file written by yourself) using System.Data / / datasetnamespace WebApplication {public partial class Login: System.Web.UI.Page {protected void Page_Load (object sender, EventArgs e) {} / login button / protected void btnLogin_Click (object sender) is used later EventArgs e) {/ / user table Sys_User column PersonStatus is "normal" before you can log in otherwise prompt the account status as the content in PersonStatus / / column PersonCode as user name PassWord password / / the encrypted string saved by PassWord in the database .Ext _ DecryptString () To decrypt Ext_EncryptString (); to encrypt string userName= txtUserName.Text.Trim (); / / .Trim () is the empty character string passWord = txtPwd.Text.Trim () before and after the string is removed; / / .Ext _ IsNullOrEmpty () is a function written by yourself in another file to determine whether the string is an empty character (you can also use userName== "", etc.) if (userName.Ext_IsNullOrEmpty ()) {ScriptHelper.ShowAlertScript ("Please enter your user name!") ; / / the pop-up form prompts return;} if (passWord.Ext_IsNullOrEmpty ()) {ScriptHelper.ShowAlertScript ("Please enter the password!") ; return;} / / filter the number of data with user name userName in the Sys_User table. A value of 0 means there is no such user, and a value of 1 means yes. 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;} / / filter out the PersonStatus value with user name userName in the Sys_User table. DataSet dsStatus = SqlHelper.GetData ("select PersonStatus from Sys_User where PersonCode='" + userName + "'"); / / fetch the value of the column named PersonStatus in the first row of the first table in dsStatus (small database) string personStatus = dsStatus.Tables [0] .Rows [0] ["PersonStatus"] .ToString (); if (personStatus! = "normal") {ScriptHelper.ShowAlertScript ("user status incorrect:" + personStatus); return } / / pay attention to the encryption of the password. After the null character is encrypted, it is not a null character. The passwords in the database are encrypted characters. In actual comparison, the characters encrypted by the actual input characters need to be compared with the characters in the database. / / string sql = "select * from Sys_User where PersonCode=' {0} 'and Password=' {1}"; / / DataSet dsUser = SqlHelper.GetData (sql, userName, passWord.Ext_EncryptString ()) / / if (dsUser.Tables [0] .Rows.Count! = 1) / / {/ / ScriptHelper.ShowAlertScript ("incorrect password!") ; / / return; / /} / / Cryptography 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 ("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 jumps to the home page Response.Redirect ("index.aspx") After reading this article, I believe you have a certain understanding of "how to use some functions of DataSet to log in to the website". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report