57 lines
1.7 KiB
C#

using Manager.Framework.Helpers;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Manager.Framework.Business
{
public class ProfileLogic
{
private readonly ILogger<ProfileLogic> _logger;
/// <summary>
/// Scrypt algorithm pepper
/// </summary>
private const string PasswordsPepper = "m6rOay9Sg8pDGFRyHVWBWLZ8DahGdYgX";
public ProfileLogic(ILogger<ProfileLogic> logger)
: base()
{
_logger = logger;
}
public void TestPassword(string email, string userPassword, string password)
{
if (string.IsNullOrWhiteSpace(email))
{
_logger.LogError($"Authenticate error: No e-mail provided");
throw new UnauthorizedAccessException("Authentication error");
}
if (string.IsNullOrEmpty(password))
{
_logger.LogError($"Authenticate error: No password provided");
throw new UnauthorizedAccessException("Authentication error");
}
if (!PasswordUtils.Compare(userPassword, password, PasswordsPepper))
{
_logger.LogError($"Authenticate error: passwords doesn't match");
throw new UnauthorizedAccessException("Authentication error");
}
}
/// <summary>
/// Hash a password
/// </summary>
/// <param name="password">Password to hash</param>
/// <returns>Hashed password</returns>
public string HashPassword(string password)
{
return PasswordUtils.Encode(password, PasswordsPepper);
}
}
}