首页 > 编程 > .NET > 正文

ASP.NET中散列加密密码

2024-07-10 13:10:10
字体:
来源:转载
供稿:网友
private void loginbutton_click(object sender,system.eventargs e)
{
        string sql=string.format("select password from administrator where adminid='{0}',useridbox.text);
        sqlconnection conn=new sqlconnection(configurationsettings.appsettings["connectionstring"]);
        sqldatareader myreader=new sqlcommand(sql,conn).executereader();
        if(myreader.read())
        {
                string hashed=formsauthentication.hashpasswordforstoringinconfigfile(passwordtextbox.text,"sha1");
                //将用户输入的密码哈希后再与数据库是的哈希值进行比较
                if(hash==myreader["password"]).tostring())
                {
                        formsauthentication.redirectfromloginpage(useridbox.text,true);//转到请求页
                }
                else
                        result.text="密码错误";
        }
        else
                result.text="用户不存在";
        conn.close();
}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表