public LoginResponse Authenticate(LoginRequest login) { try { var user = _repository.GetByPropertyIncluding(u => u.Email == login.Email); if (user == null) { throw new AppException(MessagesAPI.USER_NOT_FOUND); } login.Password = Util.GetSha256Hash(new SHA256CryptoServiceProvider(), login.Password); if (_repository.GetByPropertyIncluding(u => u.Email == login.Email && u.PasswordHash == login.Password) == null) { throw new AppException(MessagesAPI.USER_OR_PASSWORD_INVALID); } long expireMinutes = long.Parse(_configuration["Jwt:Minutes"]); string issuer = _configuration["Jwt:Issuer"]; string secretKey = _configuration["Jwt:SecretKey"]; return(JWT.BuildToken(login.Email, expireMinutes, issuer, secretKey, user.FirstName)); } catch (Exception e) { throw e; } }
public IActionResult CreateToken(IFormCollection user) { IActionResult response = Unauthorized(); var context = new HarmonyContext(); bool isAuthorized = context.users.Any(u => user["email"] == u.Name && user["pass"] == u.Password); if (isAuthorized) { var tokenString = JWT.BuildToken(_config); response = Ok(new { token = tokenString }); } return(response); }
AuthResultViewModel IUserService.Authenticate(UserDTO user) { var userDB = _repository.GetUserByEmail(user.Email); if (userDB == null) { throw new Exception("Not found"); } if (userDB.PasswordHash.Equals(PasswordCript(user.Password))) { return(JWT.BuildToken(user.Email, _appSettings.Secret, _appSettings.ExpiresIn, _appSettings.Issuer)); } return(null); }