Class: Moped::Protocol::Commands::Authenticate
- Inherits:
-
Moped::Protocol::Command
- Object
- Query
- Moped::Protocol::Command
- Moped::Protocol::Commands::Authenticate
- Defined in:
- lib/moped/protocol/commands/authenticate.rb
Overview
Implementation of the authentication command for Mongo. See: www.mongodb.org/display/DOCS/Implementing+Authentication+in+a+Driver for details.
Instance Attribute Summary
Attributes inherited from Query
#collection, #database, #fields, #flags, #full_collection_name, #length, #limit, #op_code, #request_id, #selector, #skip
Instance Method Summary collapse
- #build_auth_command(username, password, nonce) ⇒ Object
-
#digest(username, password, nonce) ⇒ String
nonce.
-
#initialize(database, username, password, nonce) ⇒ Authenticate
constructor
Create a new authentication command.
Methods inherited from Moped::Protocol::Command
Methods inherited from Query
#log_inspect, #receive_replies
Methods included from Message
included, #inspect, #receive_replies, #serialize
Constructor Details
#initialize(database, username, password, nonce) ⇒ Authenticate
Create a new authentication command.
command.
24 25 26 |
# File 'lib/moped/protocol/commands/authenticate.rb', line 24 def initialize(database, username, password, nonce) super database, build_auth_command(username, password, nonce) end |
Instance Method Details
#build_auth_command(username, password, nonce) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/moped/protocol/commands/authenticate.rb', line 42 def build_auth_command(username, password, nonce) { authenticate: 1, user: username, nonce: nonce, key: digest(username, password, nonce) } end |
#digest(username, password, nonce) ⇒ String
nonce.
33 34 35 36 37 |
# File 'lib/moped/protocol/commands/authenticate.rb', line 33 def digest(username, password, nonce) Digest::MD5.hexdigest( nonce + username + Digest::MD5.hexdigest(username + ":mongo:" + password) ) end |