You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3.01-QCM_MuscuMaths/Blazor/Models/Administrator.cs

31 lines
985 B

using Microsoft.AspNetCore.Cryptography.KeyDerivation;
using Microsoft.AspNetCore.Identity;
using System.Collections.Generic;
using System.Security.Cryptography;
namespace Blazor.Models
{
public class Administrator : PasswordHasher<string>
{
public int Id { get; private set; }
public string Username { get; private set; }
public string HashedPassword { get; set; }
private byte[] salt = RandomNumberGenerator.GetBytes(128 / 8); // for password hash
Administrator(int id, string username, string password)
{
this.Id = id;
this.Username = username;
// got this hashed password
this.HashedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2(
password: password!,
salt: salt,
prf: KeyDerivationPrf.HMACSHA256,
iterationCount: 100000,
numBytesRequested: 256 / 8)
);
}
}
}