/// <summary>
        /// Authenticates a username and password using a specific <see cref="IConnection"/> instance. The password will
        /// be encrypted before being sent to the server.
        /// </summary>
        /// <param name="connection">An implementation of <see cref="IConnection"/> which represents a TCP connection to a Couchbase Server.</param>
        /// <param name="username">The username or bucket name to authentic against.</param>
        /// <param name="password">The password to authenticate against.</param>
        /// <returns>True if succesful.</returns>
        public bool Authenticate(IConnection connection, string username, string password)
        {
            Username = username;
            Password = password ?? string.Empty;

            var temp = connection;

            var operation = new SaslStart(MechanismType, (VBucket)null, _transcoder, SaslFactory.DefaultTimeout);
            Log.LogDebug("Authenticating socket {0} with opaque {1}", temp.Identity, operation.Opaque);

            var result = _ioService.Execute(operation, connection);
            if (result.Status == ResponseStatus.AuthenticationContinue)
            {
                var challenge = result.Message;
                var reply = ComputeResponse(challenge);

                operation = new SaslStep(MechanismType, reply, _transcoder, SaslFactory.DefaultTimeout);
                result = _ioService.Execute(operation, connection);
            }

            if (result.Status == ResponseStatus.AuthenticationError)
            {
                var tempResult = result;
                Log.LogDebug("Authentication for socket {0} failed: {1}", temp.Identity, tempResult.Message);
            }
            else if (result.Status != ResponseStatus.Success)
            {
                var tempResult = result;
                Log.LogDebug("Authentication for socket {0} failed for a non-auth related reason: {1} - {2}", temp.Identity, tempResult.Message, tempResult.Status);
                if (operation.Exception != null)
                {
                    Log.LogDebug("Throwing exception for connection {0}", temp.Identity);
                    throw operation.Exception;
                }
            }
            else
            {
                Log.LogDebug("Authentication for socket {0} succeeded.", temp.Identity);
            }

            return result.Status == ResponseStatus.Success;
        }
        /// <summary>
        /// Authenticates a username and password using a specific <see cref="IConnection"/> instance. The password will
        /// be encrypted before being sent to the server.
        /// </summary>
        /// <param name="connection">An implementation of <see cref="IConnection"/> which represents a TCP connection to a Couchbase Server.</param>
        /// <param name="username">The username or bucket name to authentic against.</param>
        /// <param name="password">The password to authenticate against.</param>
        /// <returns>True if succesful.</returns>
        public bool Authenticate(IConnection connection, string username, string password)
        {
            var authenticated = false;
            Username = username;
            Password = password ?? string.Empty;
           
            var temp = connection;
            Log.Debug(m => m("Authenticating socket {0}", temp.Identity));

            var operation = new SaslStart(MechanismType, null, _converter);
            var result = _ioStrategy.Execute(operation, connection);
            if (result.Status == ResponseStatus.AuthenticationContinue)
            {
                var challenge = result.Message;
                var reply = ComputeResponse(challenge);

                operation = new SaslStep(MechanismType, reply, _converter);
                result = _ioStrategy.Execute(operation, connection);
            }

            authenticated = result.Status == ResponseStatus.Success &&
                   result.Value.Equals("Authenticated");

            if (result.Status == ResponseStatus.AuthenticationError)
            {
                var tempResult = result;
                Log.Debug(m => m("Authentication for socket {0} failed: {1}", temp.Identity, tempResult.Message));
            }
            else if (result.Status != ResponseStatus.Success)
            {
                var tempResult = result;
                Log.Debug(m => m("Authentication for socket {0} failed: {1}", temp.Identity, tempResult.Message));
                if (operation.Exception != null)
                {
                    throw operation.Exception;
                }
            }
            else
            {
                Log.Debug(m => m("Authentication for socket {0} succeeded.", temp.Identity));
            }

            return authenticated;
        }