Your homepage or website you manage has various passwords that need to be protected. There are many security risks when you directly store passwords in databases or files. Therefore, encrypted password storage is the most common practice. Encryption in ASP. NET is very easy .. . Net sdk provides the CookieAuthentication class. The HashPasswordForStoringInConfigFile method can directly use the MD5 and SHA1 algorithms. Example: <br>
File: encrypting. aspx <br>
<% @ Page language = "c #" Codebehind = "encrypting. cs" AutoEventWireup = "false" Inherits = "encrypting. encrypting" %> <br>
<Html> <Meta name = "GENERATOR" Content = "Microsoft Visual Studio 7.0"> <br>
<Meta name = "CODE_LANGUAGE" Content = "C #"> <Body> <br>
<Br>
<Form method = "post" runat = "server"> <br>
<P> </p> <br>
<P> <br>
<Asp: TextBox id = TextBox1 runat = "server"> </asp: TextBox> <br>
<Asp: Button id = Button1 runat = "server" Text = "encrypting"> </asp: Button> </p> <br>
<P> Encrypting Password (MD5): <br>
<Asp: Label id = MD5 runat = "server"> </asp: Label> </p> <br>
</Form> <br>
<Br>
</Body> <Br>
File: encrypting. cs <br>
<Br>
Namespace encrypting <br>
{<Br>
Using System; <br>
Using System. Collections; <br>
Using System. ComponentModel; <br>
Using System. Data; <br>
Using System. Drawing; <br>
Using System. Web; <br>
Using System. Web. SessionState; <br>
Using System. Web. UI; <br>
Using System. Web. UI. WebControls; <br>
Using System. Web. UI. HtmlControls; <br>
Using System. Web. Security; <br>
/// <Summary> <br>
/// Summary description for encrypting. <br>
/// </Summary> <br>
Public class encrypting: System. Web. UI. Page <br>
{<Br>
Protected System. Web. UI. WebControls. Label MD5; <br>
Protected System. Web. UI. WebControls. Button Button1; <br>
Protected System. Web. UI. WebControls. TextBox TextBox1; <br>
<Br>
Public encrypting () <br>
{<Br>
Page. Init + = new System. EventHandler (Page_Init); <br>
} <Br>
Protected void Page_Load (object sender, EventArgs e) <br>
{<Br>
If (! IsPostBack) <br>
{<Br>
// <Br>
// Evals true first time browser hits the page <br>
// <Br>
} <Br>
} <Br>
Protected void Page_Init (object sender, EventArgs e) <br>
{<Br>
// <Br>
// CODEGEN: This call is required by the ASP + Windows Form Designer. <br>
// <Br>
InitializeComponent (); <br>
} <Br>
/// <Summary> <br>
/// Required method for Designer support-do not modify <br>
/// The contents of this method with the code editor. <br>
/// </Summary> <br>
Private void InitializeComponent () <br>
{<Br>
Button1.Click + = new System. EventHandler (this. button#click); <br>
This. Load + = new System. EventHandler (this. Page_Load); <br>
} <Br>
Public void button#click (object sender, System. EventArgs e) <br>
{<Br>
MD5.Text = CookieAuthentication. HashPasswordForStoringInConfigFile (TextBox1.Text, "MD5"); <br>
// SHA1 use CookieAuthentication. HashPasswordForStoringInConfigFile (TextBox1.Text, "SHA1"); <br>
} <Br>
} <Br>
} <Br>
Note: The namespace of CookieAuthentication class is System. Web. Security.