using System.Security.Cryptography;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using Microsoft.Extensions.Identity.Core;
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Identity;
public static class Program
public static void Main()
Console.WriteLine("Hello World");
string time = DateTime.Now.ToLongTimeString();
Console.WriteLine("The current time is {0}", time);
using (RandomNumberGenerator rng = RandomNumberGenerator.Create())
Console.WriteLine(Convert.ToBase64String(HashPasswordV2("GZYCVgaQ@xkE6qO7juCh",rng)));
Console.WriteLine(PasswordHelper.HashPassword("GZYCVgaQ@xkE6qO7juCh"));
public static string Sha256(this string input)
using (var sha = SHA256.Create())
var bytes = Encoding.UTF8.GetBytes(input);
var hash = sha.ComputeHash(bytes);
return Convert.ToBase64String(hash);
private static byte[] HashPasswordV2(string password, RandomNumberGenerator rng)
const KeyDerivationPrf Pbkdf2Prf = KeyDerivationPrf.HMACSHA1;
const int Pbkdf2IterCount = 1000;
const int Pbkdf2SubkeyLength = 256 / 8;
const int SaltSize = 128 / 8;
byte[] salt = new byte[SaltSize];
byte[] subkey = KeyDerivation.Pbkdf2(password, salt, Pbkdf2Prf, Pbkdf2IterCount, Pbkdf2SubkeyLength);
var outputBytes = new byte[1 + SaltSize + Pbkdf2SubkeyLength];
Buffer.BlockCopy(salt, 0, outputBytes, 1, SaltSize);
Buffer.BlockCopy(subkey, 0, outputBytes, 1 + SaltSize, Pbkdf2SubkeyLength);
public static class PasswordHelper
private static readonly PasswordHasher<IdentityUser> _passwordHasher = new PasswordHasher<IdentityUser>();
public static string HashPassword(string password)
var user = new IdentityUser();
return _passwordHasher.HashPassword(user, password);
public static bool VerifyPassword(string hashedPassword, string providedPassword)
var user = new IdentityUser();
var result = _passwordHasher.VerifyHashedPassword(user, hashedPassword, providedPassword);
return result == PasswordVerificationResult.Success;