利用DataSet部分功能實現網站登入

來源:互聯網
上載者:User

標籤: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;

}

//注意密碼的加密,Null 字元加密後便不是Null 字元了。資料庫中的密碼是加密後的字元,實際比較中需要用實際輸入字元經加密得到的字元與資料庫中的比較

//判斷密碼 法一

//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部分功能實現網站登入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.