class EM::Mongo::Database

Public Instance Methods

authenticate(username, password) click to toggle source
# File lib/em-synchrony/em-mongo.rb, line 11
def authenticate(username, password)
  auth_result = self.collection(SYSTEM_COMMAND_COLLECTION).first({'getnonce' => 1})

  auth                 = BSON::OrderedHash.new
  auth['authenticate'] = 1
  auth['user']         = username
  auth['nonce']        = auth_result['nonce']
  auth['key']          = EM::Mongo::Support.auth_key(username, password, auth_result['nonce'])

  auth_result2 = self.collection(SYSTEM_COMMAND_COLLECTION).first(auth)
  if EM::Mongo::Support.ok?(auth_result2)
    true
  else
    raise AuthenticationError, auth_result2["errmsg"]
  end
end