Class: EM::Mongo::Database

Inherits:
Object
  • Object
show all
Defined in:
lib/em-synchrony/em-mongo.rb

Instance Method Summary collapse

Instance Method Details

#authenticate(username, password) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# 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