main project split, authpassword endpoint created
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Core.Helpers;
|
||||
|
||||
public interface IPasswordHasher
|
||||
{
|
||||
PasswordHashData CreateHash(string password);
|
||||
bool ValidatePassword(PasswordHashData hash, string password);
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Core.Helpers;
|
||||
|
||||
public record PasswordHashData(
|
||||
byte[] Hash,
|
||||
string Salt
|
||||
);
|
||||
@@ -0,0 +1,39 @@
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Konscious.Security.Cryptography;
|
||||
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Core.Helpers;
|
||||
|
||||
public class PasswordHasher : IPasswordHasher
|
||||
{
|
||||
private const string RandomPasswordCharacters = "QWERTYUIOPASDFGHJKLZXCVBNMqwertyuiopasdfghjklzxcvbnm1234567890!@#$%^&*()-_=+[{]};:'\"\\|,<.>/?";
|
||||
|
||||
public PasswordHashData CreateHash(string password)
|
||||
{
|
||||
string salt = RandomNumberGenerator.GetString(RandomPasswordCharacters, 20);
|
||||
byte[] hash = ComputeHash(password, salt);
|
||||
PasswordHashData data = new PasswordHashData(hash, salt);
|
||||
return data;
|
||||
}
|
||||
|
||||
public bool ValidatePassword(PasswordHashData hash, string password)
|
||||
{
|
||||
byte[] actualHash = hash.Hash;
|
||||
byte[] checkedHash = ComputeHash(password, hash.Salt);
|
||||
bool checkResult = checkedHash.SequenceEqual(actualHash);
|
||||
return checkResult;
|
||||
}
|
||||
|
||||
protected byte[] ComputeHash(string password, string salt)
|
||||
{
|
||||
Argon2id hashFunction = new Argon2id(Encoding.UTF8.GetBytes(password))
|
||||
{
|
||||
Salt = Encoding.UTF8.GetBytes(salt),
|
||||
DegreeOfParallelism = 8,
|
||||
MemorySize = 65536,
|
||||
Iterations = 4
|
||||
};
|
||||
byte[] hash = hashFunction.GetBytes(32);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace TimetableDesigner.Backend.Services.Authentication.Core.Helpers;
|
||||
|
||||
public class TokenGenerator
|
||||
{
|
||||
/*
|
||||
public TokenGenerator(IConfiguration configuration, DatabaseContext databaseContext)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public string GenerateAccessToken(Account account)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task<string> GenerateRefreshTokenAsync(Account account)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public async Task<string> ExtendRefreshTokenAsync()
|
||||
{
|
||||
|
||||
}*/
|
||||
}
|
||||
Reference in New Issue
Block a user