Reputation: 15144
I have a Registrations
table which new users get put into. A later process creates a database for that user, and inserts an ASP.NET Identity User record from the data in the registration table (email & name).
I'd like to extend this so that at the point of registration, users can enter their password, which will then be set up in the new database.
To do this properly, I'd need to create a SecurityStamp
value and then encrypt the password using that to get the PasswordHash
, I believe. So then I would store these values in the registrations table, and then I could copy them into the user's new database when that is set up, and they would be able to log in with the password they registered.
How would I do this - generate the SecurityStamp
and then hash the password?
Upvotes: 2
Views: 13679
Reputation: 127
Use this namespace
using Microsoft.AspNetCore.Identity;
to generate a hash use
var pass = new PasswordHasher<object>().HashPassword(null, "your password");
to test your password hash
var passCheck = new PasswordHasher<object>().VerifyHashedPassword(null, hashedpassword, "your test password");
return ((int)passCheck) == 1 ? "correct password" : "invalid password";
Upvotes: 0
Reputation: 35106
SecurityStamp
can be anything random, non-repeatable - Guid.NewGuid().ToString()
does the job nicely.
For password hashing UserManager
has property PasswordHasher
that does password hashing for you:
var userManager = new UserManager(context);
var passwordHash = userManager.PasswordHasher.HashPassword("mySecurePassword");
Upvotes: 9