I'm working on an open source project using ASP.NET MVC 5 and Identity 2 and I'm wondering how to create the first(root) user in my application.
I've searched it on Google, and the only solution I found is to integrate the whole process into the Seed() function:
// From http://stackoverflow.com/questions/27498921/creating-asp-net-identity-user-in-seed-method-of-db-initializer
protected override void Seed(EvContext context)
{
//Add other entities using context methods
ApplicationUserManager manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context));
var user = new ApplicationUser { Email = "admin@myemail.com" ,UserName = "admin@myemail.com"};
var result = await manager.CreateAsync(user, "Temp_123");//this line gives error. obviously await cannot be used in non- async method and I cannot make Seed async
}
But as this is a open source project, I don't want the password to be shown on the code but be implemented somewhere while deploying. Someone tells me that I can use OWIN, but I can't find any solutions. What's your solution? Thanks!
1- If your users download the source code and they will compile/deploy it in Visual studio: Put these kind of default or seed in WebConfig and read it in your class. See an example here
2- If your users normally deploy a compiled version, I have theses suggestions:
In my opinion it is not a bad solution to provide first user with a known login and password. The deployment procedure should have steps to change the initial password.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.