[CSHARP-1026] Need to be able to convert a password to its hash value using c# Created: 06/Aug/14  Updated: 05/Apr/19  Resolved: 04/Apr/15

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Major - P3
Reporter: Jaya Assignee: Unassigned
Resolution: Done Votes: 0
Labels: question
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

I am trying to come up with a C# code to add users to a mongodb database.
I have the below code, and need the password to be in a password hash format to insert it into system.users. Can you tell me if there any built-in function in c#, or any other price of code that I can use to convert a password into the hash format before inserting it into system.users?

var user = new MongoUser("foouser", new PasswordEvidence("foopassword"), true); var database = server.GetDatabase("admin"); var usersCollection = database.GetCollection("system.users");
var userDocument = new BsonDocument
{

{ "user", user.Username }

,

{ "pwd", user.PasswordHash }

,

{ "roles", new BsonArray() }

,
{ "otherDBRoles", new BsonDocument("productDB", new BsonArray

{ "readWrite" }

) } }; usersCollection.Insert(userDocument);


Generated at Wed Feb 07 21:38:28 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.