码迷,mamicode.com
首页 > Web开发 > 详细

利用DataSet部分功能实现网站登录

时间:2017-06-26 15:39:49      阅读:155      评论:0      收藏:0      [点我收藏+]

标签:username   用户名   select   controls   gen   小数   lin   password   筛选   

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using ZG.Common;

using System.Data;

namespace WebApplication

{

public partial class Login:System.Web.UI.Page

{

protected void Page_Load(object sender,EventArgs e)

{

}

///<summary>

///登录按钮

///</summary>

///<param name="sender"></param>

///<param name="e"></param>

protected void btnLogin_Click(object sender,EventArgs e)

{

//用户表 Sys_User 列PersonStatus为“正常”才可登录,不然提示账户状态为PersonStatus内的内容

//列PersonCode为用户名Password为密码

//数据库中PassWord保存的为加密后的 字符串.Ext_DecryptString();为解密Ext_EncryptString();为加密

string userName=txtUserName.Text.Trim();

string passWord=txtPwd.Text.Trim();

//.Ext_IsNullOrEmpty()是在另一个文件中自己编写的函数,用于判断字符串是否为空字符

if(userName.Ext_IsNullOrEmpty())

{

ScriptHelper.ShowAlertScript("请输入用户名!");

return;

}

if(passWord.Ext_IsNullOrEmpty())

{

ScriptHelper.ShowAlertScript("请输入密码!");

return;

}

//在Sys_User 表中筛选出用户名为userName的数据数量,如果为0表示没有该用户,为1表示有

DataSet ds=SqlHelper.GetData("select count(*)from Sys_User where PersonCode=‘"+userName+"‘");

if(ds.Tables[0].Rows[0][0].ToString() !="1")

{

ScriptHelper.ShowAlertScript("用户名不存在!"0;

return;

}

//在SYS_User表中筛选出用户名为userName 的PersonStatus值

DataSet dsStatus=SqlHelper.GetData("select PersonStatus from Sys_User where PersonCode‘"+userName+"‘");

//取出dsStatus(小数据库)中([0])第一张表的第一行中名为PersonStatus的列的值

string personStatus=dsStatus.Tables[0].Rows[0]["PersonStatus"].ToString();

if(personStatus !="正常")

{

ScriptHelper.ShowAlertScript("用户状态不正确:"+personStatus);

return;

}

//注意密码的加密,空字符加密后便不是空字符了。数据库中的密码是加密后的字符,实际比较中需要用实际输入字符经加密得到的字符与数据库中的比较

//判断密码 法一

//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("密码不正确!");

//return;

//}

//判断密码 法二

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("密码不正确!");

return;

}

Session["UserName"].dsUser.Tables[0].Rows[0]["PersonCode"].ToString();

Session["LoginUser"]=dsUser.Tables[0].Rows["PersonName"].ToString();

Session["UserID"]=dsUser.Tables[0].Rows[0]["ItemID"].ToString();

//如果登录成功,跳转到首页

Response.Redirect("index.aspx");

}

}

}

利用DataSet部分功能实现网站登录

标签:username   用户名   select   controls   gen   小数   lin   password   筛选   

原文地址:http://www.cnblogs.com/zzp0320/p/7080739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!