MongoDB.Driver.Database.Hash C# (CSharp) Метод

Hash() статический приватный Метод

static private Hash ( string text ) : string
text string
Результат string
        internal static string Hash(string text)
        {
            MD5 md5 = MD5.Create();
            byte[] hash = md5.ComputeHash(Encoding.Default.GetBytes(text));
            return BitConverter.ToString(hash).Replace("-","").ToLower();
        }

Usage Example

        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);
            }
        }
All Usage Examples Of MongoDB.Driver.Database::Hash