asp.net一个简单的登陆系统代码

来源:互联网 发布:mac文件在哪 编辑:程序博客网 时间:2024/05/17 08:46
 
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