Skip to content

Instantly share code, notes, and snippets.

@Svetomech
Created January 13, 2016 22:21
Show Gist options
  • Save Svetomech/cdf142257c9c724c5e3e to your computer and use it in GitHub Desktop.
Save Svetomech/cdf142257c9c724c5e3e to your computer and use it in GitHub Desktop.
using System.Security.Cryptography;
public byte[] GetPasswordHash(string username, string password, string salt)
{
// get salted byte[] buffer, containing username, password and some (constant) salt
byte[] buffer;
using (MemoryStream stream = new MemoryStream())
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(salt);
writer.Write(username);
writer.Write(password);
writer.Flush();
buffer = stream.ToArray();
}
// create a hash
SHA1 sha1 = SHA1.Create();
return sha1.ComputeHash(buffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment