AuthSystem

This commit is contained in:
Artemy
2025-06-18 12:08:21 +07:00
parent de8d97e5bf
commit 2c2c2b805c
12 changed files with 230 additions and 10 deletions
@@ -0,0 +1,33 @@
using Govor.Core.Infrastructure.Extensions;
using Govor.Core.Repositories;
using Govor.Core.Services;
namespace Govor.API.Services.Authentication;
public class AuthService : IAccountService
{
private readonly IPasswordHasher _passwordHasher;
private readonly IUsersRepository _usersRepository;
public AuthService(IUsersRepository usersRepository, IPasswordHasher passwordHasher)
{
_usersRepository = usersRepository;
_passwordHasher = passwordHasher;
}
public Task RegistrationAsync(string name, string password)
{
throw new NotImplementedException();
}
public async Task<string> LoginAsync(string name, string password)
{
if (await _usersRepository.ExistsUsernameAsync(name) == false)
throw new UserNotRegisteredException(name);
throw new NotImplementedException();
}
}
public class UserAlreadyExistException(string username) : Exception($"{username} is already exists!") { }
public class UserNotRegisteredException(string username) : Exception($"{username} is not registered!") { }
+16
View File
@@ -0,0 +1,16 @@
using Govor.Core.Infrastructure.Extensions;
namespace Govor.API.Services;
public class PasswordHasher : IPasswordHasher
{
public string Hash(string password)
{
return BCrypt.Net.BCrypt.HashPassword(password);
}
public bool Verify(string hashedPassword, string providedPassword)
{
return BCrypt.Net.BCrypt.Verify(hashedPassword, providedPassword);
}
}