MD5加密方法

MD5加密方法调用
  1. #region MD5加密算法  
  2.   
  3.    
  4.   
  5.         /// <summary>  
  6.   
  7.         /// MD5加密算法  
  8.   
  9.         /// </summary>  
  10.   
  11.         /// <paramname="str">字符串</param>  
  12.   
  13.         /// <paramname="code">加密方式,16或32</param>  
  14.   
  15.         /// <returns></returns>  
  16.   
  17.         public  string MD5(string str, int code)  
  18.   
  19.         {  
  20.   
  21.             if(code == 16) //16位MD5加密(取32位加密的9~25字符)  
  22.   
  23.             {  
  24.   
  25.                 return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToUpper().Substring(8, 16);  
  26.   
  27.             }  
  28.   
  29.             else//32位加密  
  30.   
  31.             {  
  32.   
  33.                 return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str,"MD5").ToUpper();  
  34.   
  35.             }  
  36.   
  37.         }  
  38. [html]  view plain copy
    1. protectedvoid btnlogin_Click(objectsender, EventArgs e)//登陆click事件  
    2.   
    3.     {  
    4.   
    5.         stringpassword = MD5(txtpw,32).ToString();//调用加密方法,将密码加密,然后与数据库中的对比是否相同  
    6.   
    7. }  
    8.   
    9. 页面源码:  
    10.   
    11. <body>  
    12.   
    13.     <form id="form1" runat="server">  
    14.   
    15.     <div>  
    16.   
    17.     <asp:Label ID="labname" runat="server" Text="用户名"></asp:Label>  
    18.   
    19.    <asp:TextBox ID="txtname"runat="server"></asp:TextBox>  
    20.   
    21.     <asp:Label ID="labpw" runat="server" Text="密码"></asp:Label>  
    22.   
    23.     <asp:TextBox ID="txtpw" runat="server" TextMode="Password"></asp:TextBox>  
    24.   
    25.     <asp:Button ID="btnlogin" runat="server" Text="登录" onclick="btnlogin_Click" />  
    26.   
    27.     </div>  
    28.   
    29.     </form>  
    30. </body>  


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值