Chinaunix首页 | 论坛 | 博客
  • 博客访问: 140148
  • 博文数量: 27
  • 博客积分: 1840
  • 博客等级: 上尉
  • 技术积分: 480
  • 用 户 组: 普通用户
  • 注册时间: 2006-08-09 11:07
文章分类

全部博文(27)

文章存档

2009年(2)

2008年(25)

我的朋友

分类:

2008-11-04 12:40:46

利用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");
阅读(685) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~