asp.net| algorithm your home page or you manage the site has a variety of password need to protect, put the password directly in the database or file there are many security risks, so password encryption after storage is the most common practice. Implementing encryption in ASP.net is easy. The Cookieauthentication class is available in the. NET SDK, where the HashPasswordForStoringInConfigFile method can directly use the MD5 and SHA1 algorithms. Examples are as follows:
File:encrypting.aspx
<%@ Page language= "C #" codebehind= "Encrypting.cs" autoeventwireup= "false" inherits= "encrypting.encrypting"%>
<meta name= "generator" content= "Microsoft Visual Studio 7.0" >
<meta name= "Code_language" content= "C #" ><body>
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 Browser hits the page
//
}
}
protected void Page_Init (object sender, EventArgs e)
{
//
Codegen:this the call are required by the asp+ Windows Form Designer.
//
InitializeComponent ();
}
<summary>
Required to Designer support-do not modify
The contents is 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");
}
}
}
Note: The namespace of the class Cookieauthentication is System.Web.Security.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.