我已经把注册的代码写好了。密码加了密,可以写进数据库里。但是我要实现登陆,不知道该怎么写代码了。请专家,高手帮帮忙,帮我写个登陆的代码,C#的,谢谢!问题是我怎么取出已经加了密的密码和登陆的密码相匹配呢?

解决方案 »

  1.   


    void Page_Load(object sender, System.EventArgs e)
      {
       string username=Request.Form.Get("UserName");
       string pwd=Request.Form.Get("PassWord");
       ConnectSql(username,pwd);
      }
      private void ConnectSql(string username,string pwd)
      {
       IDbConnection conn = null;
       try
       {
        conn = new SqlConnection("server=192.168.0.220;uid=sa;pwd=;database=text");
        conn.Open();
        string mySel="select * from [user] where name="+"'"+username+"'";
        SqlCommand com = new SqlCommand(mySel, (SqlConnection)conn);
        SqlDataReader reader = com.ExecuteReader();
        if(!reader.HasRows)
        {
         Response.Redirect("index.aspx?error=用户名错误");
        }
        else
        {
         while(reader.Read())
         {
          if(pwd!=reader.GetString(2))
           Response.Redirect("index.aspx?error=密码错误");
          else
           Response.Redirect("Main.html");
         }
        }
       }
       catch(SqlException)
       {
        Response.Write("在打开连接时出现连接级别的错误!");
       }
       finally
       {
        if(conn != null)
         conn.Close();
       }
      

  2.   

    顶楼上
    一般都是将 用户输入的密码 通过加密算法 得出新的字符串 , 如果数据库里的密码再加密的话 ,直接调用sql函数就行
      

  3.   

    string _userid = TextBox1.Text;
                    ExchangUsersEntity _ue = DataFactory<ExchangUsersSqlProvider>.CreateProvider.GetEntity(new SqlQuery("ExchangUsers", "UserName='" + _userid + "'"));
                    string _pwd = PassWordHelper.Encrypt(TextBox2.Text, _ue.Salt);
                    if (_ue.Password == _pwd)
                    {
                        Write_Log();
                        CookieHelper.CreatCookie(_ue.UserName,_ue.UserID.ToString(), _ue.Password, GetRoles(_ue.UserID));
                        Response.Redirect("~/Admin/index.aspx");
                    }
                    else
                    {
                        JScriptHelper.MessageBox(this, "登陆失败");
                    }