public User Authenticate(string userName, string password) { try { if (string.IsNullOrEmpty(userName)) { throw new ArgumentNullException(nameof(userName)); } if (string.IsNullOrEmpty(password)) { throw new ArgumentNullException(nameof(password)); } var user = context.Users.FirstOrDefault(t => string.Equals(t.UserName, userName)); if (user == null) { throw new UserNotExistException(); } if (hashProvider.CheckHash(password, user.Password)) { return(user); } throw new BadPasswordException(); } catch (Exception ex) { Log.Error(ex); throw; } }