Skip to content

Instantly share code, notes, and snippets.

@gayancc
Created November 6, 2015 06:10
Show Gist options
  • Save gayancc/dc4f0d9292071ac272db to your computer and use it in GitHub Desktop.
Save gayancc/dc4f0d9292071ac272db to your computer and use it in GitHub Desktop.
public virtual string CreatePasswordHash(string password, string saltkey, string passwordFormat = "SHA1")
{
if (String.IsNullOrEmpty(passwordFormat))
passwordFormat = "SHA1";
string saltAndPassword = String.Concat(password, saltkey);
var algorithm = HashAlgorithm.Create(passwordFormat);
if (algorithm == null)
throw new ArgumentException("Unrecognized hash name", "hashName");
var hashByteArray = algorithm.ComputeHash(Encoding.UTF8.GetBytes(saltAndPassword));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment