![clock](../themes/indigo/img/timeicon.gif)
May 29, 2015 07:48 by
Peter
In the world of network encryption is one of the very important idea to secure your users' information from outside hackers. usually once user input any password related field its getting encrypted and so put that encrypted password into database. And within the case of retrieving there are 2 process are there. You will encrypt the imputing password and match it with the field in database otherwise you can decrypt the keep password and match it with the input. I thing first one is much better and less time consuming.
![](https://dotnet4europeanhosting.hostforlife.eu/image.axd?picture=2015%2f5%2fFREE+banner+Hostforlife.png)
So, how to encrypt your inputted password field. The most common encryption technique is MD5. Here in this example I'll show you ways to encrypt a string into an encrypted password using MD5 in ASP.NET using C#. Create a new project and add a new WebForm to start your encrypted application. in the ASPX page add a new TextBox. Create a TextChange event and on the AutoPostBack property of the TextBox.
Write the following code, in the ASPX page:
<form id="form1" runat="server">
<div>
<asp:textbox autopostback="True" id="TextBox1" ontextchanged="TextBox1_TextChanged" runat="server"></asp:textbox>
Encrypted password :
<asp:label id="Label1" runat="server" text=""></asp:label>
</div>
</form>
Write the following code In the C# page:
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Security.Cryptography;
using System.Text;
using System;
namespace md5
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void TextBox1_TextChanged(object sender, EventArgs e)
{
MD5CryptoServiceProvider md5Hasher = new MD5CryptoServiceProvider();
Byte[] ePass;
UTF8Encoding encoder = new UTF8Encoding();
ePass = md5Hasher.ComputeHash(encoder.GetBytes(TextBox1.Text));
Label1.Text = Convert.ToBase64String(ePass);
}
}
}
In the Label1 you'll see the encrypted password. simply place the ePass into the database to store as an encrypted password. Your encryption is over. I hope it works for you!
Free ASP.NET 5 Hosting
Try our Free ASP.NET 5 Hosting today and your account will be setup soon! You can also take advantage of our Windows & ASP.NET Hosting support with Unlimited Domain, Unlimited Bandwidth, Unlimited Disk Space, etc.
![](https://dotnet4europeanhosting.hostforlife.eu/image.axd?picture=2015%2f5%2fhostforlife+banner.png)