c# - How to create SecurityStamp for AspNetUser in ASP .NET MVC 5 -
when create user register action whe application running application user gets securitystamp. when add user by:
if (!context.users.any()) { system.diagnostics.debug.writeline("inside"); var hasher = new passwordhasher(); try { var users = new list<applicationuser> { new applicationuser{passwordhash = hasher.hashpassword("testpass44!"), email = "informatyka4444@wp.pl", username = "informatyka4444@wp.pl"}, new applicationuser{passwordhash = hasher.hashpassword("testpass44!"), email = "informatyka4445@wp.pl", username = "informatyka4445@wp.pl"} }; users.foreach(user => context.users.addorupdate(user)); context.savechanges(); } catch (dbentityvalidationexception e) { system.diagnostics.debug.writeline("exc: "); foreach (dbentityvalidationresult result in e.entityvalidationerrors) { foreach (dbvalidationerror error in result.validationerrors) { system.diagnostics.debug.writeline(error.errormessage); } } } }
user doesn't security stamp:
and when want login get:
question: how generate securitystamp
user?
the security stamp can want. mistaken timestamp, not. overriden asp.net identity if changes on user entity. if you're working on context directly best way generate new guid , use stamp. here's simple example:
var users = new list<applicationuser> { new applicationuser { passwordhash = hasher.hashpassword("testpass44!"), email = "informatyka4444@wp.pl", username = "informatyka4444@wp.pl", securitystamp = guid.newguid().tostring() }, new applicationuser { passwordhash = hasher.hashpassword("testpass44!"), email = "informatyka4445@wp.pl", username = "informatyka4445@wp.pl", securitystamp = guid.newguid().tostring() } };
Comments
Post a Comment