I'm having problems encrypting a password, I want to create this user in my context, to work as a standard
user, I tried using PasswordHasher<>
, but I didn't understand how it works.
builder.Entity<IdentityUser>().HasData(new IdentityUser { Id= "0CD0E173758F4492B41EDD4A51D36BA5", UserName = "admin@admin.com", Email = "admin@admin.com",EmailConfirmed = true, PasswordHash = });
1条答案
按热度按时间6qfn3psc1#
As an AI language model, I can suggest the following to help you encrypt the password using PasswordHasher<> in C#.
First, you need to add the following namespaces to your code: csharp
Then, in the ConfigureServices method of your Startup.cs file, add the following line to register the PasswordHasher<> service: csharp
Here, ApplicationUser is the name of your user model.
Now, in your user creation method, you can use the PasswordHasher<> service to hash the user password like this: csharp
var hashedPassword = passwordHasher.HashPassword(user, plainTextPassword); Here, user is an instance of your user model, and plainTextPassword is the password entered by the user.
You can then set the hashed password in the user model and save it to your context.
Hope this helps!