/// <summary> /// Implements memcached's SASL auth sequence. (See the protocol docs for more details.) /// </summary> /// <param name="socket"></param> /// <returns></returns> private bool Auth(IPooledSocket socket) { SaslStep currentStep = new SaslStart(this.authenticationProvider); socket.Write(currentStep.GetBuffer()); while (!currentStep.ReadResponse(socket).Success) { // challenge-response authentication if (currentStep.StatusCode == 0x21) { currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data); socket.Write(currentStep.GetBuffer()); } else { if (log.IsWarnEnabled) log.WarnFormat("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode); // invalid credentials or other error return false; } } return true; }
/// <summary> /// Implements memcached's SASL authenticate sequence (see the protocol docs for more details.) /// </summary> /// <param name="socket"></param> /// <returns></returns> bool Authenticate(PooledSocket socket) { SaslStep step = new SaslStart(this._authenticationProvider); socket.Send(step.GetBuffer()); while (!step.ReadResponse(socket).Success) { // challenge-response authentication if (step.StatusCode == 0x21) { step = new SaslContinue(this._authenticationProvider, step.Data); socket.Send(step.GetBuffer()); } // invalid credentials or other error else { this._logger.LogWarning("Authentication failed, return code: 0x{0:x}", step.StatusCode); return(false); } } return(true); }
/// <summary> /// Implements memcached's SASL auth sequence. (See the protocol docs for more details.) /// </summary> /// <param name="socket"></param> /// <returns></returns> private bool Auth(IPooledSocket socket) { SaslStep currentStep = new SaslStart(this.authenticationProvider); socket.Write(currentStep.GetBuffer()); while (!currentStep.ReadResponse(socket).Success) { // challenge-response authentication if (currentStep.StatusCode == 0x21) { currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data); socket.Write(currentStep.GetBuffer()); } else { if (log.IsWarnEnabled) { log.WarnFormat("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode); } // invalid credentials or other error return(false); } } return(true); }
private async Task <bool> AuthAsync(PooledSocket socket) { SaslStep currentStep = new SaslStart(this.authenticationProvider); await socket.WriteAsync(currentStep.GetBuffer()); while (!(await currentStep.ReadResponseAsync(socket)).Success) { // challenge-response authentication if (currentStep.StatusCode == 0x21) { currentStep = new SaslContinue(this.authenticationProvider, currentStep.Data); await socket.WriteAsync(currentStep.GetBuffer()); } else { _logger.LogWarning("Authentication failed, return code: 0x{0:x}", currentStep.StatusCode); // invalid credentials or other error return(false); } } return(true); }
bool Authenticate(IPooledSocket socket) { var isAuthenticated = true; const int authContinue = 0x21; SaslStep step = new SaslStart(_provider); socket.Write(step.GetBuffer()); while (!step.ReadResponse(socket).Success) { if (step.StatusCode == authContinue) { step = new SaslContinue(_provider, step.Data); socket.Write(step.GetBuffer()); } else { isAuthenticated = false; break; } } return isAuthenticated; }