注册 登录
编程论坛 ASP.NET技术论坛

哪位大神能帮我把MD5加密的登陆模式换成普通的登陆模式

kick10530 发布于 2013-07-02 11:27, 615 次点击
    protected void Button1_Click(object sender, EventArgs e)
    {
     String Md5_User_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txt_User_Pwd.Text.ToString(), "MD5");  
        SqlStr = "select * from 管理员表 where 用户名='" + this.txt_User_Name.Text + "' and 密码='" + Md5_User_Pwd + "'";
        Ds = db.GetDataTableBySql(SqlStr);
        try
        {
            if (Ds.Tables[0].Rows.Count == 0)
            {
                this.Labinfo.Text = "用户名或密码错误,请重试!";
                this.txt_User_Name.Focus();
            }
            else
            {
               this.Labinfo.Text = "管理员  " + this.txt_User_Name.Text + "  恭喜您登录成功!";
               Session["Admin_UserName"] = this.txt_User_Name.Text;
            }
        }
        catch (Exception)
        {
            this.Labinfo.Text = "没有得到任何数据,请重试!";
        }
    }
3 回复
#2
party6202013-07-02 11:43
如何你数据库存的是加密后的密码,你再登陆时把加密给去了,你就等不上了
#3
kick105302013-07-02 14:51
这个是我完整的代码,管理的那里我不知道设计,我在数据库设计的密码为123456,不过我知道加密后就不是123456,;可我不知道怎么设计加密密码,
public partial class login_usercontrol : System.Web.UI.UserControl
{
    String SqlStr;
    DB db = new DB();
    DataSet Ds = new DataSet();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Login_Click(object sender, EventArgs e)
    {
        String Md5_User_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txt_User_Pwd.Text.ToString(), "MD5");
        SqlStr = "select * from 会员表 where 会员名='" + this.txt_User_Name.Text + "' and 密码='" + Md5_User_Pwd + "'";
        Ds = db.GetDataTableBySql(SqlStr);
        try
        {
            if (Ds.Tables[0].Rows.Count == 0)
            {
                this.Labinfo.Text = "用户名或密码错误,请重试!";
                this.txt_User_Name.Focus();
            }
            else
            {
                this.Labinfo.Text = "用户  " + this.txt_User_Name.Text + "  恭喜您登录成功!";
                Session["UserName"] = this.txt_User_Name.Text;
            }
        }
        catch (Exception)
        {
            this.Labinfo.Text = "没有得到任何数据,请重试!";
        }
    }
    protected void btn_Register_Click(object sender, EventArgs e)
    {
        Response.Redirect("zhuce.aspx");
    }


    protected void Button1_Click(object sender, EventArgs e)
    {
     String Md5_User_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txt_User_Pwd.Text.ToString(), "MD5");  
        SqlStr = "select * from 管理员表 where 用户名='" + this.txt_User_Name.Text + "' and 密码='" + Md5_User_Pwd + "'";
        Ds = db.GetDataTableBySql(SqlStr);
        try
        {
            if (Ds.Tables[0].Rows.Count == 0)
            {
                this.Labinfo.Text = "用户名或密码错误,请重试!";
                this.txt_User_Name.Focus();
            }
            else
            {
               this.Labinfo.Text = "管理员  " + this.txt_User_Name.Text + "  恭喜您登录成功!";
               Session["Admin_UserName"] = this.txt_User_Name.Text;
            }
        }
        catch (Exception)
        {
            this.Labinfo.Text = "没有得到任何数据,请重试!";
        }
    }
}
#4
party6202013-07-02 15:52
如果你设计的数据后台不是加密的,你把
String Md5_User_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txt_User_Pwd.Text.ToString(), "MD5");  
换为:String Md5_User_Pwd =this.txt_User_Pwd.Text.ToString();即可

如果你想设计的数据库是加密的,你需要在注册代码中把密码文本框加密:String Md5_User_Pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txt_User_Pwd.Text.ToString(), "MD5");这样你的登陆就不用动啦
1