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();
}
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); } }