private void ReadUserDataCompleted(ClientMessage.ReadStreamEventsBackwardCompleted completed,
                                    AuthenticationRequest authenticationRequest)
 {
     try
     {
         if (completed.Result != ReadStreamResult.Success)
         {
             authenticationRequest.Unauthorized();
             return;
         }
         var userData = completed.Events[0].Event.Data.ParseJson <UserData>();
         if (userData.LoginName != authenticationRequest.Name)
         {
             authenticationRequest.Error();
             return;
         }
         if (userData.Disabled)
         {
             authenticationRequest.Unauthorized();
         }
         else
         {
             AuthenticateWithPasswordHash(authenticationRequest, userData);
         }
     }
     catch
     {
         authenticationRequest.Unauthorized();
     }
 }
        private void ReadUserDataCompleted(ClientMessage.ReadStreamEventsBackwardCompleted completed,
                                           AuthenticationRequest authenticationRequest)
        {
            try {
                if (completed.Result == ReadStreamResult.StreamDeleted ||
                    completed.Result == ReadStreamResult.NoStream ||
                    completed.Result == ReadStreamResult.AccessDenied)
                {
                    if (_logFailedAuthenticationAttempts)
                    {
                        Log.Warning("Authentication Failed for {id}: {reason}", authenticationRequest.Id, "Invalid user.");
                    }
                    authenticationRequest.Unauthorized();
                    return;
                }

                if (completed.Result == ReadStreamResult.Error)
                {
                    if (_logFailedAuthenticationAttempts)
                    {
                        Log.Warning("Authentication Failed for {id}: {reason}", authenticationRequest.Id,
                                    "The system is not ready.");
                    }
                    authenticationRequest.NotReady();
                    return;
                }

                var userData = completed.Events[0].Event.Data.ParseJson <UserData>();
                if (userData.LoginName != authenticationRequest.Name)
                {
                    authenticationRequest.Error();
                    return;
                }

                if (userData.Disabled)
                {
                    if (_logFailedAuthenticationAttempts)
                    {
                        Log.Warning("Authentication Failed for {id}: {reason}", authenticationRequest.Id,
                                    "The account is disabled.");
                    }
                    authenticationRequest.Unauthorized();
                }
                else
                {
                    AuthenticateWithPasswordHash(authenticationRequest, userData);
                }
            } catch {
                authenticationRequest.Unauthorized();
            }
        }