public IUser AuthenticateUser(string username, string clearTextPassword) { UserData userData = _users.FirstOrDefault(u => u.Username.Equals(username) && u.HashedPassword.Equals(CalculateHash(clearTextPassword, u.Username)) && true); // if (userData == null) { OnUserAuthenticateFailed?.Invoke(username); this.DeAuthenticateCurrentUser(); throw new UnauthorizedAccessException(strings.AccessDeniedCredentials); } VerifyRolesHash(userData); return(AuthenticateUser(userData)); }
public User AuthenticateUser(string token) { if (string.IsNullOrEmpty(token)) { OnUserAuthenticateFailed?.Invoke("empty token"); this.DeAuthenticateCurrentUser(); throw new UnauthorizedAccessException(strings.AccessDeniedEmptyToken); } var userData = _users.FirstOrDefault(u => u.AuthenticationToken != null && u.AuthenticationToken.Equals(CalculateHash(token, string.Empty))); if (userData == null) { OnUserAuthenticateFailed?.Invoke("unknown token"); this.DeAuthenticateCurrentUser(); throw new UnauthorizedAccessException(strings.AccessDeniedInvalidToken); } VerifyRolesHash(userData); return(AuthenticateUser(userData)); }