Hash() static private method

static private Hash ( string text ) : string
text string
return string
        public void AddUser(string username, string password)
        {
            IMongoCollection users = db["system.users"];
            string           pwd   = Database.Hash(username + ":mongo:" + password);
            Document         user  = new Document().Append("user", username).Append("pwd", pwd);

            if (FindUser(username) != null)
            {
                throw new MongoException("A user with the name " + username + " already exists in this database.", null);
            }
            else
            {
                users.Insert(user);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }