日期:2014-05-19  浏览次数:20723 次

谁能编写一个利用session和数据库进行登录验证的网页?
谁能编写一个利用session和数据库(只有用户名和密码)进行登录验证的网页?


------解决方案--------------------
if (CheckLoginInfo(this.TBUserName.Text, this.TBPassWord.Text) > 0)
{
Session[ "UserName "] = this.TBUserName.Text ;
string vFUserRole = Server.UrlEncode(GetRole(this.TBUserName.Text.ToUpper()));
string vParams;
vParams = "Default.aspx?UserRole= " + vFUserRole + "&PassWord= " + this.TBPassWord.Text + "&UserName= " + this.TBUserName.Text;
Server.Transfer(vParams);
}
else
{
Response.Write( " <script defer> alert( '登录信息有误! ');window.location=window.location; </script> ");
this.TBPassWord.Text = " ";
this.TBUserName.Text = " ";*/
}
}
------解决方案--------------------
//检查是否有登录名和密码是否正确
private int CheckLoginInfo(string AUserName, string APassWord)
{
int intCount;
string strCount;
strCount = "select count(*) as FCount from tblEmployee where FActiveuser=1 and Upper(FUserName)= ' ";
strCount += this.TBUserName.Text.ToUpper() + " ' and IsNull(FPassWord, ' ')= ' " + this.TBPassWord.Text + " ' ";
SqlConnection SqlCon=new SqlConnection(strCon);
SqlCommand MyComm=new SqlCommand(strCount,SqlCon);
SqlCon.Open();
SqlDataReader dr=MyComm.ExecuteReader();
if(dr.Read())
{
intCount=Convert.ToInt16(dr[ "FCount "].ToString());
}
else
{
intCount=0;
}
dr.Close();
return intCount;
}