using Microsoft.Extensions.Logging; using System; namespace ManagerService.Helpers { public class ProfileLogic { private readonly ILogger _logger; /// /// Scrypt algorithm pepper /// private const string PasswordsPepper = "m6rOay9Sg8pDGFRyHVWBWLZ8DahGdYgX"; public ProfileLogic(ILogger 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"); } } /// /// Hash a password /// /// Password to hash /// Hashed password public string HashPassword(string password) { return PasswordUtils.Encode(password, PasswordsPepper); } } }