Generate a PasswordHash and SecurityStamp

折月煮酒 提交于 2019-12-25 04:22:13

问题


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?


回答1:


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");


来源:https://stackoverflow.com/questions/39661032/generate-a-passwordhash-and-securitystamp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!