Consolidating MVC4 and Symfony2 users into one database

I have a webapp that has a frontoffice that uses Symfony2, and a backoffice that uses ASP.NET MVC4 (before you tell me, yes, I know this is a ridiculous setting, but these are restrictions that we must adhere to) .

Now I would like to have one user table in my database from which users can log in to both frontoffice (SF2) and backoffice (MVC4). I use FOSUserBundle to manage my users on the Symfony2 side, but I have not decided which membership provider I should use for the MVC4 application part, mainly because I have no idea how to authenticate users on the ASP side.

FOSUserBundle uses SHA512 with 5000 iterations for user registration / password change. Both the hashed password and the salt of passwords are stored in the database - all this works fine. The problem is that I'm not sure how I should use this data in an MVC4 application; I did some research to find out if I can change the hashing algorithm, etc., but it requires me to create a custom membership provider, which is a little daunting for those who have not worked with MVC4 before.

Can someone point me in the right direction? It would be very grateful.

+4
source share
1 answer

You can write a custom membership provider that will query your database. Basically you need to write a class that comes from MembershipProvider and implement the methods you want to use. There are many methods, but you probably don't need to cancel them. For example, the ValidateUser method accepts a username and password, and you decide how to handle the situation.

For instance:

 public class MyCustomMembershipProvider: MembershipProvider { ... } 

and then you can register this custom membership provider in your web.config to replace it with the default:

 <membership defaultProvider="MyCustomMembershipProvider"> <providers> <clear/> <add name="MyCustomMembershipProvider" type="MvcApplication1.Providers.MyCustomMembershipProvider" /> </providers> </membership> 

Now, when inside your LogOn action you call Membership.ValidateUser , it delegates your custom provider.

+2
source

All Articles