Last active
August 14, 2018 14:58
-
-
Save imbaker/fdeedc01bfdcf9409fc1 to your computer and use it in GitHub Desktop.
Code to encode passwords using the ASP.NET Membership provider method
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://dotnetfiddle.net/wBqZSX | |
using System; | |
using System.Text; | |
using System.Security.Cryptography; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
Console.WriteLine(EncodePassword("Pa55w0rd", "Gr6NjoLK1t89g4pwjmfC1g==")); | |
} | |
public static string EncodePassword(string pass, string salt) | |
{ | |
byte[] bytes = Encoding.Unicode.GetBytes(pass); | |
byte[] src = Convert.FromBase64String(salt); | |
byte[] dst = new byte[src.Length + bytes.Length]; | |
Buffer.BlockCopy(src, 0, dst, 0, src.Length); | |
Buffer.BlockCopy(bytes, 0, dst, src.Length, bytes.Length); | |
HashAlgorithm algorithm = HashAlgorithm.Create("SHA1"); | |
byte[] inArray = algorithm.ComputeHash(dst); | |
return Convert.ToBase64String(inArray); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment