0

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.

MRebai
  • 5,344
  • 3
  • 33
  • 52
  • check out these links. [http://stackoverflow.com/questions/16605519/how-to-create-custom-websecurity-login-and-websecurity-createuserandaccount-meth][1] [http://stackoverflow.com/questions/19161726/simplemembership-mvc4-existing-database][2] [1]: http://stackoverflow.com/questions/16605519/how-to-create-custom-websecurity-login-and-websecurity-createuserandaccount-meth [2]: http://stackoverflow.com/questions/19161726/simplemembership-mvc4-existing-database – C M Aug 18 '14 at 13:51
  • @CM - really, none of those answer his question... they are all about creating custom users in SimpleMembership, which is not the same thing as trying to make SimpleMembership conform to an existing database schema (which, unfortunately is not possible for the login credential portions) – Erik Funkenbusch Aug 18 '14 at 15:09

1 Answers1

1

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.

Erik Funkenbusch
  • 92,674
  • 28
  • 195
  • 291
  • OK, i got what you say, could you please give me the best example to implement a custom membership provider. – MRebai Aug 18 '14 at 16:28
  • @MoezRebai - Well, for starters.. do you know the algorithm used to hash the original passwords? If not, then this is a moot point, since you won't succeed and might as well start over with a clean database. – Erik Funkenbusch Aug 18 '14 at 16:31
  • No i don't have any idea, also my database is empty and i can edit it at any time, my only request is how to bind that database with the custom membership – MRebai Aug 18 '14 at 16:45
  • @MoezRebai - Well, if your database is empty then why do you have to work with the existing structure? – Erik Funkenbusch Aug 18 '14 at 16:54
  • i want to work with mvc 4 and EF, thus i created my model(user) and then create my Database based on that model. Now my only demand how can i add login and register and role to that user using membership – MRebai Aug 18 '14 at 17:11