Reputation: 5474
I am working with an MVC4 application and an existing database. I want to use the default login and register defined at SimpleMembership MVC4.
I am using a table with employee information like, EmployeID, Employename, password, email...
At SimpleMembershipInitializer
I changed
WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);
to my own :
WebSecurity.InitializeDatabaseConnection("HRContext", "Employee", "EmployeeId", "EmployeName", autoCreateTables: true);
and changed the AccountController
but in vain
I just want to use my database with the default register/ login methods.I read several topics, but none of them give me a what I need.
Upvotes: 0
Views: 94
Reputation: 93434
You can't just change the tables and expect it to work for a variety of reasons. In fact, unless you're very very lucky, chances are this won't work at all because SimpleMembership has a hard coded password hashing algorithm, and you can't override it. So unless your original web app used the identical hashing alogorithm (assuming it used a hash at all) then it simply isn't going to recognize any users password.
More importantly, however, chances are that your Employee table is not the correct schema that SimpleMembership is expecting. Again, this is hard coded in SimpleMembership and not something you can change. SimpleMembership will try to create its own tables and ignore your password and other fields you want (other than username and userid, assuming userid is in the correct format)
SimpleMembership does provide a very flexible way to extend the default tables, but you are at the mercy of it's schema for the basic credential portion of it.
If you need to use this existing system, then you will have to use the legacy Membership system and create a custom membership provider. There are literally hundreds if not thousands of questions and answers already on Stack Overflow on how to do this.
Upvotes: 1