【asp.net中密码加密】ASP.NET中密码保护

更新时间:2017-07-15 来源:软件评测 点击:

【www.hzclsc.cn--软件评测】

 你的主页或者你管理的网站有各种密码需要保护,把密码直接放在数据库或者文件中存在不少安全隐患,所以密码加密后存储是最常见的做法。在ASP.NET中实现加密非常容易。.NET SDK中提供了CookieAuthentication类,其中的HashPasswordForStoringInConfigFile方法可直接使用MD5和SHA1算法。例子如下:
file: encrypting.aspx
 


 

 

Encrypting Password(MD5):
 



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 description for encrypting.
   /// 
   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();
       }
       /// 
       ///    Required method for Designer support - do not modify
       ///    the contents of this method with the code editor.
       /// 
       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。

本文来源:http://www.hzclsc.cn/ruanjianzixun/467.html

为您推荐

[rainway什么意思]Rainway软件下载地址 rainway串流switch软件在哪下载

您的位置:首页 → 单机游戏 → 游戏资讯 → Rainway软件下载地址 rainway串流switch软件在哪下载 Rainway软件下载地址 rainway串流switch软件在哪下载时间:20游戏资讯

2020-12-16 11:04:57  

苹果电脑安全性偏好设置_苹果电脑安全漏洞是什么 苹果电脑安全漏洞无需密码解锁解决办法

就在近日,有用户发现苹果电脑出现了一个重大的安全漏洞,不需要输入密码即可进入系统,但是很多用户都还不知道苹果电脑安全漏洞是什么,好奇的用户马上点击查看苹果电脑安全漏洞无需密码解锁解决办法来防范于未然教你一招

2020-12-10 23:05:05   电脑安全软件   电脑安全证书过期怎么办   顺丰寄电脑安全吗  

【nero】Nelo游戏配置要求高吗 Nelo推荐配置一览

Nelo游戏配置要求高吗?Nelo是一款由虚幻4打造的超快节奏的动作游戏,玩家可以使用四种武器形成各式各样的攻击方式,本文为大家带来Nelo售价和配置要求介绍,下面就一起来看看Nelo推荐配置一览吧。游戏资讯

2020-12-10 11:04:41   nero8中文破解版   nero刻录软件   nero10序列号  

抢红包神器抢最大的_抢红包怎么抢最大的 抢红包助手下载哪个好

时近年末,相信大家的“节目单”上除了与好友聚会叙旧、与客户更加频繁地应酬之外,还有一项必不可少的活动,那就是抢红包。记得木心有首现代诗中是这样写的,“从前的日色变得慢,车马、信件都很慢 ”的软件评测

2020-12-09 17:04:22   抢红包怎么能抢最大的   抢红包最大金额软件  

[wegame修复游戏在哪里]腾讯wegame怎么修复游戏 wegame平台修复游戏教程

您的位置:首页 → 资讯 → 游戏软件 → 腾讯wegame怎么修复游戏 wegame平台修复游戏教程 腾讯wegame怎么修复游戏 wegame平台修复游戏教程时间:2017 10 20 16:00游戏软件

2020-12-04 07:04:50   wegame游戏修复在哪里   wegame如何修复游戏