def login(database, username, password)
      getnonce = Protocol::Command.new(database, getnonce: 1)
      self.write([getnonce])
      reply = self.receive_replies([getnonce]).first
      if getnonce.failure?(reply)
        return
      end
      result = getnonce.results(reply)

      authenticate = Protocol::Commands::Authenticate.new(database, username, password, result["nonce"])
      self.write([ authenticate ])
      document = self.read.documents.first

      unless result["ok"] == 1
        # See if we had connectivity issues so we can retry
        e = Errors::PotentialReconfiguration.new(authenticate, document)
        if e.reconfiguring_replica_set?
          raise Errors::ReplicaSetReconfigured.new(e.command, e.details)
        elsif e.connection_failure?
          raise Errors::ConnectionFailure.new(e.inspect)
        end

        raise Errors::AuthenticationFailure.new(authenticate, document)
      end
      credentials[database] = [username, password]
    end
def login(database, username, password)
      getnonce = Protocol::Command.new(database, getnonce: 1)
      self.write([getnonce])
      reply = self.receive_replies([getnonce]).first
      if getnonce.failure?(reply)
        return
      end
      result = getnonce.results(reply)

      authenticate = Protocol::Commands::Authenticate.new(database, username, password, result["nonce"])
      self.write([ authenticate ])
      document = self.read.documents.first

      unless result["ok"] == 1
        # See if we had connectivity issues so we can retry
        e = Errors::PotentialReconfiguration.new(authenticate, document)
        if e.reconfiguring_replica_set?
          raise Errors::ReplicaSetReconfigured.new(e.command, e.details)
        elsif e.connection_failure?
          raise Errors::ConnectionFailure.new(e.inspect)
        end

        raise Errors::AuthenticationFailure.new(authenticate, document)
      end
      credentials[database] = [username, password]
    end
Login the user to the provided database with the supplied password.

 @example Login the user to the database.
   node.login("moped_test", "user", "pass")

 @param [ String ] database The database name.
 @param [ String ] username The username.
 @param [ String ] password The password.

 @raise [ Errors::AuthenticationFailure ] If the login failed.

 @return [ Array ] The username and password.

 @since 2.0.0