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.
26 lines
825 B
26 lines
825 B
using Microsoft.AspNetCore.Cryptography.KeyDerivation;
|
|
using System.Security.Cryptography;
|
|
|
|
namespace Blazor.Models
|
|
{
|
|
public class Player
|
|
{
|
|
public int Id { get; private set; }
|
|
public string Nickname { get; private set; }
|
|
public string HashedPassword { get; set; }
|
|
private byte[] salt = RandomNumberGenerator.GetBytes(128 / 8); // for password hash
|
|
public Player(int id, string nickname, string password)
|
|
{
|
|
Id = id;
|
|
Nickname = nickname;
|
|
HashedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2(
|
|
password: password!,
|
|
salt: salt,
|
|
prf: KeyDerivationPrf.HMACSHA256,
|
|
iterationCount: 100000,
|
|
numBytesRequested: 256 / 8)
|
|
);
|
|
}
|
|
}
|
|
}
|