Created
January 13, 2016 22:21
-
-
Save Svetomech/cdf142257c9c724c5e3e to your computer and use it in GitHub Desktop.
This file contains 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
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