/// <summary> /// Calculates the password hash. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password.</param> /// <returns>The password hash.</returns> public static string HashPassword( string username, string password ) { return(MongoUtils.Hash(username + ":mongo:" + password)); }
/// <summary> /// Adds a user to this database. /// </summary> /// <param name="credentials">The user's credentials.</param> /// <param name="readOnly">True if the user is a read-only user.</param> public virtual void AddUser( MongoCredentials credentials, bool readOnly ) { var users = GetCollection("system.users"); var user = users.FindOne(Query.EQ("user", credentials.Username)); if (user == null) { user = new BsonDocument("user", credentials.Username); } user["readOnly"] = readOnly; user["pwd"] = MongoUtils.Hash(credentials.Username + ":mongo:" + credentials.Password); users.Save(user); }