aspx Tutorial

.NET Articles,jQuery demo, asp.net with jQuery, online tutorial,Jquery, SilverLight, Javascript, asp.net,JSON, MVC,.NET Articles,demo, Web Services, .NET articles, Sharepoint 2010, visual studio 2010,Aamir Hasan,IT
Advertise Here

Advertize

wwwSW
Posted by Aamir Hasan   on Tuesday, February 22, 2011 Total Views:  

This article describes how to secure your password before saving in database or XML file etc. Attacker always try to attack the database and stole all the passwords stored in database. It's developer responsibility to encrypt the password before sending to the database. One way encryption is secure to protect the passwords. One way encryption can encrypt the password but cannot decrypt.

In this example, I have used SHA512Managed Class. The size of SHA512Managed algorithm is 512 bits.

Here’s an example

 

Default.aspx page

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title></title>

    <style>

        body

        {

            background: #fefefe;

            font-size: .80em;

            font-family: "Helvetica Neue" , "Lucida Grande";

            margin: 0px;

            padding: 0px;

            color: #222;

        }

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <h2>

        Implementing One-way Encryption in asp.net using csharp/VB.NET        </h2>

        <p>

            Password:

            <asp:TextBox ID="TextBox1" runat="server" />

            <asp:Button ID="Button1" runat="server" Text="Submit" OnClick="Button1_Click" />

            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="Enter the Password."

                ControlToValidate="TextBox1" ForeColor="Red"></asp:RequiredFieldValidator></br>

            <br />

            <asp:Label ID="Label1" runat="server" />

        </p>

    </div>

    </form>

</body>

</html>

 

Default.aspx.cs

    protected void Button1_Click(object sender, EventArgs e)

    {

        Label1.Text = "Encrypted password:  " +
                      getEncryptedCode(TextBox1.Text.Trim().ToString());

    }

    public static string getEncryptedCode(string inputString)

    {

        byte[] Hash = new System.Security.Cryptography
                      .SHA512Managed().ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(inputString));

        System.Text.StringBuilder outputString = new System.Text.StringBuilder();

        for (int i = 0; i < Hash.Length; i++)

            outputString.Append(Hash[i].ToString("x2"));

        return outputString.ToString();

    }

 

Default.aspx.vb

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)

        Label1.Text = "Encrypted password:  " +
                      getEncryptedCode(TextBox1.Text.Trim().ToString())

    End Sub

    Public Shared Function getEncryptedCode(ByVal inputString As String) As String

        Dim Hash As Byte() = New System.Security.Cryptography
                             .SHA512Managed().ComputeHash(System.Text.ASCIIEncoding.ASCII.GetBytes(inputString))

        Dim outputString As New System.Text.StringBuilder()

        For i As Integer = 0 To Hash.Length - 1

            outputString.Append(Hash(i).ToString("x2"))

        Next

        Return outputString.ToString()

    End Function

 

Note:If you forgot your password, you cannot decrypt it; you have to reset your password.

 

SHA512Managed Class Supported in .net version 1.0, 1.1, 2.0, 3.0, 3.5 and 4.O


If you have alternative solution, please comments below to share with us.

Output

Download

One-way-Encryption-cSharp.rar (1.30 kb)

One-way-EncryptionVB.rar (1.23 kb)

See live demo

Protected by Copyscape Online Plagiarism Tool

Comments (11) -

Performance Appraisal System
Performance Appraisal System Italy
2/22/2011 11:13:25 PM #

I really appreciate your professional approach. These are pieces of very useful information that will be of great use for me in future. Thanks for it.

Johnson
Johnson United States
2/23/2011 9:28:23 AM #

Try using 2048 bits of hash.
512 is very easily breakable on even ordinary hardware

Mahwish
Mahwish United Kingdom
2/24/2011 4:35:07 AM #

Great work aamir. Use x2 ,

Saba khan
Saba khan United States
2/24/2011 6:03:39 PM #

Wonderful post! I like your blog, and am a regular follower.It can bring me many useful information,keep up the good work

John
John U.A.E.
2/26/2011 11:32:57 PM #

Thank you admin, i need this script in VB.NET. Please keep it up.

SEO
SEO Australia
3/9/2011 11:15:05 PM #

Thanks aamir you doing very well job for software engineer's

2011 nfl jerseys china
2011 nfl jerseys china United States
5/8/2011 10:14:52 PM #

This looks really interesting. Thanks making the source code available.

Beats By Dre Headphones
Beats By Dre Headphones People's Republic of China
11/23/2011 2:25:00 AM #

These are pieces of very useful information that will be of great use for me in future.

air yeezy
air yeezy People's Republic of China
2/20/2012 4:58:45 PM #


I came accross your blog  recently and have been reading <a href="http://www.kanyewest-shoes.com/">air yeezy </a>along. The article is very useful, very interesting, hope to share more articles like this.Thank you for your sharing!

air yeezy
air yeezy People's Republic of China
2/20/2012 4:59:08 PM #


I came accross your blog  recently and have been reading <a href="http://www.kanyewest-shoes.com/">air yeezy </a>along. The article is very useful, very interesting, hope to share more articles like this.Thank you for your sharing!

herve leger wholesale
herve leger wholesale People's Republic of China
4/20/2012 8:38:43 PM #

Beats by dre, the 1st beam Disc-jockey headphones broad header column design as well as surface of sports ths interior of your soft leather-based material with the head performed a great decompression, in order to effectively decrease fatigue wear quite a while. In the convergence in the first beam and earmuffs, the Beats by dre redesigned the first beam offers good balance, steel group while using full texture in the metal cable drawing, plus serves your entire design of the specific headphones fashion Smart.
http://www.thehervelegerwholesale.com/
http://www.getsoccershoes.com/
http://www.thebeatsbydedre.co.uk/
www.thebeatsbydedre.co.uk/...-by-dre-pro-c-41.html
www.thebeatsbydedre.co.uk/...by-dre-solo-c-42.html
www.thebeatsbydedre.co.uk/...dre-solo-hd-c-43.html
www.thebeatsbydedre.co.uk/...-dre-studio-c-40.html
www.thebeatsbydedre.co.uk/...by-dre-tour-c-45.html
www.thebeatsbydedre.co.uk/...our-red-uk-p-159.html
www.thebeatsbydedre.co.uk/...s-lady-gaga-c-47.html
www.thebeatsbydedre.co.uk/diddybeats-c-48.html

fafafa
fafafa Slovenia
4/23/2012 2:59:48 AM #

http://www.christianlouboutinukk.org   christian louboutin
http://www.tiffanyuks.org   tiffany uk
http://www.gucciukbeltuk.org   gucci belt
http://www.frsaclouisvuittonsac.com   louis vuitton sac
http://www.chanelukoutletuks.org   chanel outlet
http://www.burberryukoutletuk.org   burberry
http://www.poloralphlaurenuko.org   ralph lauren uk

Pingbacks and trackbacks (2)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

Advertizement 1
Advertizement 2
Advertizement 3
Advertizement 4
Advertizement 5