Last active
July 26, 2019 14:08
-
-
Save ml-eds/1ce877db6bea92ad295f55184f27a81b to your computer and use it in GitHub Desktop.
Password hashing (ASPNetCore)
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; | |
using Microsoft.AspNetCore.Identity; | |
using Microsoft.Extensions.Options; | |
namespace ConsoleApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
//PasswordHasher configuration | |
PasswordHasherOptions opt = new PasswordHasherOptions(); | |
opt.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3; | |
opt.IterationCount = 12; | |
OptionsWrapper<PasswordHasherOptions> opts = new OptionsWrapper<PasswordHasherOptions>(opt); | |
//Hash password | |
PasswordHasher<Object> hash = new PasswordHasher<Object>(opts); | |
string password = hash.HashPassword(null, "fnord"); | |
Console.WriteLine("Hash of password 'fnord':" + password); | |
//Verify hash + password | |
string given = "AQAAAAEAACcQAAAAEH9zn8nECM7n0bgV+ntLs+nJGwnElpjKawrgn+wEhypGmnB/XMZTLsUASGC+6POvrw=="; | |
bool success = PasswordVerificationResult.Success == hash.VerifyHashedPassword(null, given, "fnord"); | |
Console.WriteLine("Verification of " + given + " was succes:" + success ); | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment