public string Authenticate(string username, string password) { var user = _userRepository.GetUserByCredentials(username, PasswordHelper.HashPassword(password)); if (user == null) { throw new Exception("Wrong credentials"); } return(JwtHelper.Encode(JwtHelper.ContextFromUser(user))); }