public bool Authenticate(string userName, string password) { try { WarningHandler.Debug("Authentication try: " + userName); var passwordHash = CryptoUtils.CreatePasswordHash(password); var user = UsersRepository.Users.SingleOrDefault(x => x.Login.Equals(userName) && x.PasswordHash.Equals(passwordHash)); if (user == null) { WarningHandler.Debug("Authentication failed: " + userName); return(false); } WarningHandler.Debug("Authentication success: " + userName); return(true); } catch (Exception e) { WarningHandler.Error("Error while user authentication: " + userName, e); return(false); } }
public override void Validate(string userName, string password) { try { WarningHandler.Debug("Authentication try: " + userName); var passwordHash = CryptoUtils.CreatePasswordHash(password); var user = UsersRepository.Users.SingleOrDefault(x => x.Login.Equals(userName) && x.PasswordHash.Equals(passwordHash)); if (user == null) { throw new FaultException("Login or password not valid", new FaultCode(ServiceFaultCodes.AccessDenied)); } WarningHandler.Debug("Authentication success: " + userName); } catch (FaultException e) { WarningHandler.Debug("Authentication failed: " + userName); throw e; } catch (Exception e) { WarningHandler.InfoFormat(e, "Error while user authenticate: [{0}]", userName); throw new FaultException("Error while user authenticate: " + userName, new FaultCode(ServiceFaultCodes.InternalError)); } }