自己实现用户登录验证 本帖最后由 lan_wang 于 2010-11-25 08:58:43 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e){ bool Authenticated = false; Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password); e.Authenticated = Authenticated; if (Authenticated == true) { Response.Redirect("Home.aspx"); }}private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password){ bool boolReturnValue = false; // Insert code that implements a site-specific custom // authentication method here. // This example implementation always returns false. //这里是你数据库的信息 string strConnection = "server=dtpxp-skumari;database=master;uid=sa;pwd=;"; SqlConnection Connection = new SqlConnection(strConnection); String strSQL = "Select * From Employee"; SqlCommand command =new SqlCommand(strSQL, Connection); SqlDataReader Dr; Connection.Open(); Dr=command.ExecuteReader(); while (Dr.Read()) { if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString())) { boolReturnValue = true; } Dr.Close(); return boolReturnValue; }} 最简单的一种 string cmdtxt="select id from [ENTUserAccount] where username='"+用户名 +"'" and password='"+密码+"'";sqlcommand cmd=new sqlcommand(str,con);con.open();object o=cmd.executeScalar();con.close()if(o==DBnull.value)return false;//登陆失败 账号密码错误elsereturn true;//账号密码正确 返回ture然后你可以在页面调用这个方法,如果返回值是true 你就可以跳转页面,否则就不跳转。但是最好的登陆方法使用存储过程,安全 谢谢各位!二楼三楼的意思我明白,实现后自然就能OK。但我刚刚才注意到,那个用户表中居然没有“密码”这一字段……真是晕倒看来只有把那本书全部看完后再来请教各位3KS! 服务器用Ajax提交数据没反应 请求给一个aspx处理一个页面中发过来的两个form的方法 asp.net如何异步处理,求解!!!! URL链接问题 急急急急急急急急急急 关于asp.net里的Media Player控件的使用 DataGrid动态加载BoundColumn列的问题! .NET2005里还有没有水晶报表,听说没有了,是不是真的??????? 【用js给页面img标签加一个a标签】 dropdownlist问题 asp.net无法显示web控件,也无法对web控件编程 页面中“关键字: 描述问题” 问题 大家解决一下 robots.txt文件的一个写法
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
bool Authenticated = false;
Authenticated = SiteLevelCustomAuthenticationMethod(Login1.UserName, Login1.Password);
e.Authenticated = Authenticated;
if (Authenticated == true)
{
Response.Redirect("Home.aspx");
}
}
private bool SiteLevelCustomAuthenticationMethod(string UserName, string Password)
{
bool boolReturnValue = false;
// Insert code that implements a site-specific custom
// authentication method here.
// This example implementation always returns false.
//这里是你数据库的信息
string strConnection = "server=dtpxp-skumari;database=master;uid=sa;pwd=;";
SqlConnection Connection = new SqlConnection(strConnection);
String strSQL = "Select * From Employee";
SqlCommand command =new SqlCommand(strSQL, Connection);
SqlDataReader Dr;
Connection.Open();
Dr=command.ExecuteReader();
while (Dr.Read())
{
if ((UserName == Dr["name"].ToString()) & (Password == Dr["Password"].ToString()))
{
boolReturnValue = true;
}
Dr.Close();
return boolReturnValue;
}
}
sqlcommand cmd=new sqlcommand(str,con);
con.open();object o=cmd.executeScalar();con.close()
if(o==DBnull.value)
return false;//登陆失败 账号密码错误
else
return true;//账号密码正确 返回ture
然后你可以在页面调用这个方法,如果返回值是true 你就可以跳转页面,否则就不跳转。
但是最好的登陆方法使用存储过程,安全
二楼三楼的意思我明白,实现后自然就能OK。
但我刚刚才注意到,那个用户表中居然没有“密码”这一字段……真是晕倒
看来只有把那本书全部看完后再来请教各位
3KS!