介绍
小编给大家分享一下如何利用数据集部分功能实现网站登录,希望大家阅读完这篇文章之后都有所收获、下面让我们一起去探讨吧!
首先,我之前必须完成过注册,并把个人信息存入数据库中。
其次,这部分的个别对象是存于某些文档中的,需要引用命名空间。
using 系统; using System.Collections.Generic; using 来; using 包含; using System.Web.UI; using System.Web.UI.WebControls; using ZG.Common;//后面用到ScriptHelper对象(ScriptHelper.cs是自己编写的cs文件) using System.Data;//后面用到数据集 namespace WebApplication { ,public partial  class Login : System.Web.UI.Page ,{ ,protected void  employee (object ,发送方,EventArgs e) ,{ }///,& lt; summary> ,///登录按钮///,& lt;/summary> ,///& lt; param name=皊ender"祝辞& lt;/param> ,///& lt; param name=癳"祝辞& lt;/param> protected void  btnLogin_Click (object ,发送方,EventArgs e) ,{//用户表,Sys_User 列PersonStatus 为,“正常”,才可登录,不然提示账户状态为PersonStatus内的内容//列PersonCode为用户名,密码为密码//数据库中密码保存的为加密后的,字符串.Ext_DecryptString();为解密,Ext_EncryptString();为加密 string userName =, txtUserName.Text.Trim ();//.Trim()是去掉字符串前后的空字符 string passWord =, txtPwd.Text.Trim ();//.Ext_IsNullOrEmpty()是在另一个文件中自己编写的函数,用于判断字符串是否为空字符(也可用用户名=="等判断) if (userName.Ext_IsNullOrEmpty ()) ,{ ,ScriptHelper.ShowAlertScript(“请输入用户名!“);//弹出窗体提示 返回; ,} if (passWord.Ext_IsNullOrEmpty ()) ,{ ,ScriptHelper.ShowAlertScript(“请输入密码!“); 返回; ,}//在Sys_User 表中筛选出用户名为用户名的数据数量,如果为0表示没有该用户,为1表示有。 DataSet ds =, SqlHelper.GetData (“select  count(*),得到Sys_User where PersonCode=& # 39;“, +,用户名+,“& # 39;“); ,if (ds.Tables [0] .Rows [0] [0] .ToString (), !=,“1“) ,{ ,ScriptHelper.ShowAlertScript(“用户名不存在!“); 返回; ,}//在Sys_User 表中筛选出用户名为用户名的PersonStatus 值。 DataSet dsStatus =, SqlHelper.GetData (“select  PersonStatus 得到Sys_User where PersonCode=& # 39;“, +, userName +,“& # 39;“);//取出dsStatus(小数据库)中([0])第一张表的第一行中名为PersonStatus的列的值 string personStatus =, dsStatus.Tables [0] .Rows [0] [“PersonStatus"] .ToString (); ,if (personStatus !=,“正常“) ,{ ScriptHelper.ShowAlertScript(“用户状态不正确:“,+,personStatus); ,返回; ,}//注意密码的加密,空字符加密后便不是空字符了。数据库中的密码是加密后的字符,实际比较中需要用实际输入字符经加密得到的字符与数据库中的比较//判断密码,法一 ,,,,,//string sql =,“select *,得到Sys_User where PersonCode=& # 39;{0} & # 39;,以及密码=& # 39;{1}& # 39;“; ,,,,,//DataSet dsUser =, SqlHelper.GetData (string.Format (sql,,用户名,passWord.Ext_EncryptString ())); ,,,,,//if (dsUser.Tables [0] .Rows.Count !=1) ,,,,,//{ ,,,,,//,,ScriptHelper.ShowAlertScript(“密码不正确!“); ,,,,,//,,返回; ,,,,,//}//判断密码,法二 ,,,,,string sql =,“select *,得到Sys_User where PersonCode=& # 39; {0} & # 39;,“; ,,,,,DataSet dsUser =, SqlHelper.GetData (string.Format (sql,,用户名); ,,,,,if (dsUser.Tables [0] .Rows [0] [“PassWord"] .ToString (), !=, passWord.Ext_EncryptString ()) ,,,,,{ ,,,,,,,ScriptHelper.ShowAlertScript(“密码不正确!“); ,,,,,,,返回; ,,,,,} 会话(“UserName"),=, dsUser.Tables [0] .Rows [0] [“PersonCode"] .ToString (); (“LoginUser"),会话,=,dsUser.Tables [0] .Rows [0] [“PersonName"] .ToString (); (“UserID"),会话,=,dsUser.Tables [0] .Rows [0] [“ItemID"] .ToString (); ,//如果登录成功,跳转到首页 Response.Redirect (“index.aspx"); ,} ,} }
看完了这篇文章,相信你对“如何利用数据集部分功能实现网站登录”有了一定的了解,如果想了解更多相关知识,欢迎关注行业资讯频道,感谢各位的阅读!