项目合作 | 广告服务 | 联系我们 | 友情链接 | 链接代码 | 短信服务 | 给我留言 | 返回首页                    
设为首页
加入收藏
ASP技术 | ASP.NET技术 | JSP技术 | Servlet技术 | PHP技术 | JS技术 | C#技术 | Java技术 | B/S应用 | B/S论坛 | 下载区
 
 自定义DataGrid分页设置
 ASP.NET中使用Caching
 一个文件上传的类
 ASP.NET中在线用户统计
 网站间共享数据的WebService
 ASP.NET里的事务处理
 VS.NET下web项目源代码管理
 用TreeView实现树菜单
 在DataGrid中创建一个弹出式窗.
 有关DataGrid显示数据的问题
 让Calendar在页面调用时才显示.
 在web.config中建立数据库连接.
 实时天气及24小时天气预报
 数据库中图片存储及读取
 如何在窗体和窗体之间传送数据.
 利用ASP.NET来访问Excel文档
 使用嵌套的Repeater控件
 用asp.net画饼图
 实现DataList控件的分页
 用ASP.NET加密口令
 使用RangeValidator
 C#做的ASP.NET登錄篇
 ASP.NET图象处理详解
 在网页中动态的生成一个图片
 检测含有中文字符串的实际长度.
 用ASP.NET和XML做的新闻系统
 如何在asp.net中操作文件
 ASP.NET验证控件祥解
 ASP.NET中的事务处理和异常处理.
 ASP.NET上传文件的实例
 在ASP.NET中访问SQL Server
 ASP.NET安全身份验证的实现
 ASP.NET中密码保护
 在ASP.NET中使用.NET组件
 实现Web文件的上传
 asp.net实现pop功能
 ASP.NET创建文件并写入内容
 在ASP.NET中动态生成图形
 ASP.NET中文显示之两种解决方法.
 ASP.NET验证控件详解
 在ASP.NET中使用.NET组件
 资料验证的asp.net程序
 一个完整的案例
 在ASP+的Form中检查填写是否正.
 增加修改删除一个数据
 个性化的分页实现
 用ASP.NET识别浏览器
 DataGrid学习七
 DataGrid学习六
 DataGrid学习五
 DataGrid学习四
 DataGrid学习三
 DataGrid学习二
 DataGrid学习一
 DataTable控件的使用
 RegularExpressionValidator
 ViewState初探
 ASP.Net的Session
 ASP.Net的Application
 AdRotator控件的使用
 ASP.Net的Cookie实现
 XML、DataSet、DataGrid结合二.
 XML、DataSet、DataGrid结合一.
 ASP.NET中的Web Controls
 ASP.NET程序数组功能调用
 ASP.NET与ASP的不同
 ASP.net发送Email
 ASP.NET、JSP及PHP之间的抉
 

ASP.NET中密码保护

摘自:化境编程                   人气:3479

  你的主页或者你管理的网站有各种密码需要保护,把密码直接放在数据库或者文件中存在不少安全隐患,所以密码加密后存储是最常见的做法。在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>&nbsp;</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。

如有疑问,请赐电邮:webmaster@chinabs.net  OICQ:28194826
技术开发:深圳市百越软件工作室
中国BS网版权所有     Copyright chinabs.net