public bool Authenticate(string username, string password)
{
Document nonceResult = this.SendCommand("getnonce");
String nonce = (String)nonceResult["nonce"];
if (nonce == null){
throw new MongoException("Error retrieving nonce", null);
}
string pwd = Database.Hash(username + ":mongo:" + password);
Document auth = new Document();
auth.Add("authenticate", 1.0);
auth.Add("user", username);
auth.Add("nonce", nonce);
auth.Add("key", Database.Hash(nonce + username + pwd));
try{
this.SendCommand(auth);
return true;
}catch(MongoCommandException){
return false;
}
}