利用FormsAuthentication 类的HashPasswordForStoringInConfigFile
方法实现用户登录口令加密
1、创建password类
using
System.Web.Security;引用加密类所在的命明空间
下段代码为加密码过程
public class
jmpassword
{
public string EncryptPassword(string
PasswordString,string PasswordFormat )
{
string
EncryptPassword="";
if (PasswordFormat=="SHA1")
{
EncryptPassword=FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString
,"SHA1");
return EncryptPassword;
} else if
(PasswordFormat=="MD5")
{
EncryptPassword=FormsAuthentication.HashPasswordForStoringInConfigFile(PasswordString
,"MD5");
return EncryptPassword;
}
else
{
EncryptPassword="";
return
EncryptPassword;
}
}
}
2、在表单中引用类,并将密码框输入的值进行加密
jmpassword Password=new
jmpassword();
string
password=Password.EncryptPassword(txtpassword.Text.ToString(),"SHA1")+Password.EncryptPassword(txtpassword.Text.ToString(),"MD5");
阅读(550) | 评论(0) | 转发(0) |