Asp. password protection in net, the use of MD5 and SHA1 algorithms

Source: Internet
Author: User
Tags md5 sha1 password protection visual studio
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>

<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>
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 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.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.