Skip to content

Instantly share code, notes, and snippets.

@cleftheris
Created November 15, 2018 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleftheris/dd38c52a22487b41c0603429c0bbcea4 to your computer and use it in GitHub Desktop.
Save cleftheris/dd38c52a22487b41c0603429c0bbcea4 to your computer and use it in GitHub Desktop.
xUnit test demonstrating MySQL generated sha1 password hashing in c#
using System;
using System.Security.Cryptography;
using System.Text;
using Xunit;
namespace Identity.Tests
{
public class PasswordTests
{
[InlineData("test", "*94BDCEBE19083CE2A1F959FD02F964C7AF4CFC29")]
[Theory]
public void MySqlHash(string password, string hash) {
var keyArray = Encoding.UTF8.GetBytes(password);
var enc = new SHA1Managed();
var encodedKey = enc.ComputeHash(enc.ComputeHash(keyArray));
var builder = new StringBuilder(encodedKey.Length);
foreach (var b in encodedKey) {
builder.Append(b.ToString("X2"));
}
var generatedHash = "*" + builder.ToString();
Assert.Equal(hash, generatedHash);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment