I am working on a relatively simple login system for Symfony2.
I have the basics down and working just fine.
What makes this a bit special is I need a way to provide a third value (an ecosystem value). The user names in my database are not unique on their own, but make unique pairs with an ecosystem value.
The ecosystem value is provided by the form that they log in from.
How can I use this ecosystem value be taken into consideration when performing a login?
Take a look at the Cookbook tutorial on How to load Security Users from the Database (the Entity Provider) - specifically the part about Authenticating Someone with a Custom Entity Provider.
This part explains how to alter/create a UserProviderInterface
to allow logging in via an e-mail address or username. Obviously, this isn't what you want, but - it should be relatively trivial to modify the code to also query/validate against your 3rd login parameter.
Ideally, you will probabaly want to create your own UserProvider and luckily, there is a cookbook tutorial just for that: How to create a custom User Provider.
Update: To have the 3rd login option handled and passed to your custom providers (created above), you will also need to create a custom Authentication Provider. Take a look at (yet another) cookbook article on How to create a custom Authentication Provider. This article is tailored for handling extra request header parameters for authentication, but using this example you should be able to swap out request headers for request POST values.
Use the cookbook article to get an understanding of how authentication with Symfony2 works, but use (and extend) the username/password functionality of Symfony2 and just include your 3rd parameter. Some classes to look at:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With