using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using SCard;
using System.Data.SqlClient;
public partial class admin_Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
lit.Text = "";
Session["adminName"] = null;
}
}
protected void btnRes_Click(object sender, EventArgs e)
{
txtPwd.Text = "";
txtUserName.Text = "";//用户名密码设置为空白
txtUserName.Focus();//用户名取得焦点
}
protected void btnOK_Click(object sender, EventArgs e)
{
string pwd=txtPwd.Text.ToString();
string uname=txtUserName.Text.ToString();
if (uname.Length == 0 || pwd.Length == 0)
{
lit.Text = "alert('用户名密码不能为空!')";
}
else
{
if (isAdmin(uname, pwd))
{
Session["adminName"] = uname;
Response.Redirect("Index.aspx");
}
else
{
lit.Text = "alert('用户名或者密码错误!')";
}
}
}
private bool isAdmin(string strAdmin, string strPassword)
{
bool bTemp = false;
strPassword = FormsAuthentication.HashPasswordForStoringInConfigFile(strPassword, "MD5");
DBConn myDB = new DBConn();
string mySql = "select * from admin where username='" + strAdmin + "' and password='" + strPassword + "'";
SqlDataReader mydr = myDB.getDataReader(mySql);
if (mydr.Read())
{
bTemp = true;
}
else
{
bTemp = false;
}
mydr.Close();
myDB.Close();
return bTemp;
}
}