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:

enter image description here

and when want login get:

enter image description here

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

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -