Pages

Subscribe:

Ads 468x60px

Friday, September 9, 2011

how to encrypt password in ASP.net using C#

if you are searching for an encrypting password hashing algorithm than you are at right place, make sure before using this method that this algo is one way, means it has no decrypt method. just copy and past
here is the code for your aspx.cs file.

firstly include following files.
using System.Security.Cryptography;
using System.Text;
here is the function call.
protected void LoginButton_Click()

    {
   txt_lable.Text = getEncryptedCode(txt_passwrod.Text);
    
} 

 public static string getEncryptedCode(string inputString)
        {
            byte[] tmpSource;
            byte[] tmpHash;
            int index = 0;
            int hashLength = 0;
            tmpSource = ASCIIEncoding.ASCII.GetBytes(inputString);
            tmpHash = new SHA512Managed().ComputeHash(tmpSource);
            hashLength = tmpHash.Length;
            StringBuilder outputString = new StringBuilder(hashLength);
            for (index = 0; index < hashLength; index++)
            {
                outputString.Append(tmpHash[index].ToString("X2"));
            }
            return outputString.ToString();
        } 

No comments:

Post a Comment