40 lines
1.1 KiB
C#
40 lines
1.1 KiB
C#
using Microsoft.AspNetCore.Identity;
|
|
using System.Numerics;
|
|
using DeluxeBackend.Models;
|
|
|
|
namespace DeluxeBackend.Services
|
|
{
|
|
public interface IPasswordService
|
|
{
|
|
void setPassword(Account player, string password);
|
|
PasswordVerificationResult VerifyPassword(Account player, string passowrd);
|
|
}
|
|
|
|
public class PasswordService : IPasswordService
|
|
{
|
|
private readonly ILiteDbService db;
|
|
private readonly PasswordHasher<Account> _hasher = new PasswordHasher<Account>();
|
|
|
|
public PasswordService(ILiteDbService _db)
|
|
{
|
|
db = _db;
|
|
}
|
|
|
|
public void setPassword(Account player, string password)
|
|
{
|
|
player.PasswordHash = _hasher.HashPassword(player, password);
|
|
db.Accounts.Update(player);
|
|
}
|
|
|
|
public PasswordVerificationResult VerifyPassword(Account player, string passowrd)
|
|
{
|
|
if (player.PasswordHash == null)
|
|
{
|
|
return PasswordVerificationResult.Failed;
|
|
}
|
|
return _hasher.VerifyHashedPassword(player, player.PasswordHash, passowrd);
|
|
}
|
|
|
|
}
|
|
}
|