Asp.net登陆代码
private void btnLogin_Click(object sender, EventArgs e)
{
string sql = "SELECT userid FROM Users WHERE UserName = '" + txtUserName.Text.Replace("'","_") + "' AND UserPassword = '" + System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "md5") + "'";
//使用上面类似的SQL语句向数据库执行查询,如果用户是合法的,将会返回数据。
if (...) //根据条件判定用户是合法的
{
//下面的语句告诉.NET发送一个验证Cookie给用户:
System.Web.Security.FormsAuthentication.SetAuthCookie(userid, false)
Response.Redirect("afterlogi
{
string sql = "SELECT userid FROM Users WHERE UserName = '" + txtUserName.Text.Replace("'","_") + "' AND UserPassword = '" + System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(txtPassword.Text, "md5") + "'";
//使用上面类似的SQL语句向数据库执行查询,如果用户是合法的,将会返回数据。
if (...) //根据条件判定用户是合法的
{
//下面的语句告诉.NET发送一个验证Cookie给用户:
System.Web.Security.FormsAuthentication.SetAuthCookie(userid, false)
Response.Redirect("afterlogi
本文介绍了一个ASP.NET登录功能的实现代码。通过SQL查询语句验证用户名和MD5加密后的密码来判断用户身份的有效性,并使用FormsAuthentication.SetAuthCookie设置认证Cookie。
879

被折叠的 条评论
为什么被折叠?



