[asp.net] 对指定字符串进行MD5加密
View Code
/// <summary>
/// 根据配置对指定字符串进行 MD5 加密
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static string GetMD5(string s)
{
//md5加密
s = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s, "md5").ToString();
return s.ToLower().Substring(8, 16);
}
登陆验证:
View Code
protected void btnLogin_Click(object sender, EventArgs e)
{
if (!Utils.CheckVilidateCode(txtVilidateCode.Text))
{
//验证码错误;
return;
}
AdminUser admin = AdminUser.GetModel(txtName.Text.Trim());
if (admin == null)
{
//提示用户不存在
return;
}
if (admin.Pass != Utils.GetMD5(txtPass.Text))
{
//提示密码错误;
return;
}
AdminUser.CurrentAdmin = admin;
Response.Redirect("Admin_Index.aspx");
}
技术文档