CSMongo.Commands.MongoDatabaseCommands.Authenticate C# (CSharp) Метод

Authenticate() публичный статический Метод

Handles logging into the specified database
public static Authenticate ( MongoDatabase database, string username, string password ) : MethodResult
database MongoDatabase
username string
password string
Результат CSMongo.Results.MethodResult
        public static MethodResult Authenticate(MongoDatabase database, string username, string password)
        {
            //open the connection to the database
            database.Connection.Open();

            //get the values required
            GetNonceResult nonce = MongoDatabaseCommands.GetNonce(database);
            if (!nonce.HasNonce) {
                throw new MongoServerException(string.Format("Unable to get a nonce value from {0}.", database.Connection.Host));
            }

            //issue the actual command
            string key = MongoDatabaseCommands.HashPassword(username, password, nonce.Nonce);
            CommandResponse result = MongoDatabaseCommands.RunCommand(
                database,
                new {
                    authenticate = Mongo.CommandArgument,
                    user = username,
                    nonce = nonce.Nonce,
                    key = key
                });

            //Do not close the connection at this point
            //since we need access to keep the connection
            //alive
            return new MethodResult(result.GetDefaultResponse());
        }