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

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -