public async Task <CommandResult> Handle(AuthenticateUserCommand request, CancellationToken cancellationToken) { var stopwatch = new Stopwatch(); stopwatch.Start(); var user = await _entitiesRepository.GetFirstOrDefaultAsync <User>(u => u.Username == request.Username.ToLower()); if (user != null) { if (!user.IsDisabled) { if (SecurityUtility.IsMatchingHash(request.Password, user.HashedPassword, user.Salt)) { return(new CommandResult() { ObjectRefId = user.Username, ElapsedMs = stopwatch.ElapsedMilliseconds, Type = CommandResultTypes.None }); } } } return(new CommandResult() { ElapsedMs = stopwatch.ElapsedMilliseconds, ObjectRefId = null, Type = CommandResultTypes.None }); }
public void SetEncryptionKey(string key) { lock (_locker) { if (state.EncryptionKeyHash == null) { GenerateEncryptionKeyAsync(key).GetAwaiter().GetResult(); } else { if (SecurityUtility.IsMatchingHash(key, state.EncryptionKeyHash, state.EncryptionKeySalt)) { _encryptionKey = key; Initialized = true; } else { throw new InvalidPrivateKeyException("Key is not matching the cluster's decryption key."); } } } }
public bool IsEncryptionKeyValid(string key) { return(SecurityUtility.IsMatchingHash(key, state.EncryptionKeyHash, state.EncryptionKeySalt)); }