国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET中密碼保護,MD5和SHA1算法的使用

2024-07-10 12:58:20
字體:
來源:轉載
供稿:網友
你的主頁或者你管理的網站有各種密碼需要保護,把密碼直接放在數據庫或者文件中存在不少安全隱患,所以密碼加密后存儲是最常見的做法。在asp.net中實現加密非常容易。.net sdk中提供了cookieauthentication類,其中的hashpasswordforstoringinconfigfile方法可直接使用md5和sha1算法。例子如下:
file: encrypting.aspx
<%@ page language="c#" codebehind="encrypting.cs" autoeventwireup="false" inherits="encrypting.encrypting" %>
<html><head>
    <meta name="generator" content="microsoft visual studio 7.0">
    <meta name="code_language" content="c#"></head>
  <body>

    <form method="post" runat="server">
<p> </p>
<p>
<asp:textbox id=textbox1 runat="server"></asp:textbox>
<asp:button id=button1 runat="server" text="encrypting"></asp:button></p>
<p>encrypting password(md5):
<asp:label id=md5 runat="server"></asp:label></p>
     </form>

  </body></html>

file:encrypting.cs

namespace encrypting
{
    using system;
    using system.collections;
    using system.componentmodel;
    using system.data;
    using system.drawing;
    using system.web;
    using system.web.sessionstate;
    using system.web.ui;
    using system.web.ui.webcontrols;
    using system.web.ui.htmlcontrols;
    using system.web.security;
    /// <summary>
    ///    summary description for encrypting.
    /// </summary>
    public class encrypting : system.web.ui.page
    {
  protected system.web.ui.webcontrols.label md5;
  protected system.web.ui.webcontrols.button button1;
  protected system.web.ui.webcontrols.textbox textbox1;

public encrypting()
{
     page.init += new system.eventhandler(page_init);
        }
        protected void page_load(object sender, eventargs e)
        {
            if (!ispostback)
            {
                //
                // evals true first time browser hits the page
                //
            }
        }
        protected void page_init(object sender, eventargs e)
        {
            //
            // codegen: this call is required by the asp+ windows form designer.
            //
            initializecomponent();
        }
        /// <summary>
        ///    required method for designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void initializecomponent()
  {
   button1.click += new system.eventhandler (this.button1_click);
   this.load += new system.eventhandler (this.page_load);
  }
  public void button1_click (object sender, system.eventargs e)
  {
   md5.text = cookieauthentication.hashpasswordforstoringinconfigfile(textbox1.text,"md5");
   //sha1 use cookieauthentication.hashpasswordforstoringinconfigfile(textbox1.text,"sha1");
  }
    }
}
注意:類cookieauthentication的namespace是system.web.security。 
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 霍邱县| 冕宁县| 五大连池市| 香港| 万源市| 镇江市| 白河县| 环江| 博乐市| 富民县| 邯郸市| 施秉县| 武陟县| 霍州市| 兴义市| 长春市| 西贡区| 濮阳市| 通州市| 武平县| 五峰| 德化县| 马龙县| 松江区| 克山县| 泾川县| 天气| 勐海县| 沙坪坝区| 那曲县| 杭锦后旗| 岚皋县| 吴江市| 界首市| 阳泉市| 蛟河市| 蒲城县| 怀柔区| 琼海市| 莒南县| 武川县|