?? index.aspx.cs
字號:
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.Security;
namespace WebApplication2
{
/// <summary>
/// index 的摘要說明。
/// </summary>
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.TextBox txtAccount;
protected System.Web.UI.WebControls.TextBox txtPassword;
protected System.Web.UI.WebControls.CustomValidator CustomValidator1;
protected System.Web.UI.WebControls.CustomValidator CustomValidator2;
protected System.Web.UI.WebControls.Button btnLogin;
protected System.Web.UI.WebControls.Button btnRegister;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator1;
protected System.Web.UI.WebControls.RequiredFieldValidator RequiredFieldValidator2;
protected System.Web.UI.WebControls.Label Label1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此處放置用戶代碼以初始化頁面
}
#region Web 窗體設(shè)計器生成的代碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 該調(diào)用是 ASP.NET Web 窗體設(shè)計器所必需的。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </summary>
private void InitializeComponent()
{
this.CustomValidator1.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.CustomValidator1_ServerValidate);
this.CustomValidator2.ServerValidate += new System.Web.UI.WebControls.ServerValidateEventHandler(this.CustomValidator2_ServerValidate);
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
this.btnRegister.Click += new System.EventHandler(this.btnRegister_Click);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
// 注冊帳戶
private void btnRegister_Click(object sender, System.EventArgs e)
{
Response.Redirect("Register.aspx");
}
// 判斷用戶是否存在
private void CustomValidator1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
string Account=args.Value;
Bank b=new Bank();
if(b.judge(Account))
{
args.IsValid=true;
}
else
{
args.IsValid=false;
}
}
// 判斷用戶密碼是否正確
private void CustomValidator2_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args)
{
string Account=this.txtAccount.Text;
string Password=args.Value;
// 用hash加密,由于數(shù)據(jù)庫password的類型太小所以要取前10位
string hashPassword=FormsAuthentication.HashPasswordForStoringInConfigFile(Password,"sha1");
hashPassword=hashPassword.Substring(0,10);
Bank b=new Bank();
// if(b.check(Account,Password))
if(b.check(Account,hashPassword))
{
args.IsValid=true;
}
else
{
args.IsValid=false;
}
}
// 登錄
private void btnLogin_Click(object sender, System.EventArgs e)
{
if(this.IsValid)
{
Response.Redirect("Login.aspx?Account="+this.txtAccount.Text);
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -