Add remaining project files
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user