Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Use two auth drivers for two database tables
  • I've some problem with config in app>config>auth.php.

    return array(
        'driver'                 => array('Masterdriver', 'Admindriver'),
        'verify_multiple_logins' => false,
        'salt'                   => 'put_your_salt_here', 
        'iterations'             => 10000,
    );


    I'm gonna create two login for Admin and Master. For admin, it only take username and password but for master login, it is hotel_id, username, password. So, I think it's impossible to use only one auth driver for the login. I also think verify_multiple_logins => true will also not work since their login fields are not the same. My Question is "Is there a way to solve like this problem?". If it has, please could you show me the way.

  • This is not going to work with the standard methods, Auth is designed around username and password.

    Are they using a different backend, in other words, could there be an admin user "abc" and one or more master users "abc" (each with a different hotel id)?
  • Yes @Harro Verton, they have different backends. Admin login localhost/admin/login and master login localhost/master/login. When master login, it needs to fill hotel_id, username and password. Is it possible by creating two own drivers or is there any other good ways? But I don't know how to do it. 
  • The problem is that you need a local unique user id, which you will never have with multiple backends for logins.

    Our Opauth implementation solves that using the users_providers table, which will map a master user to a "dummy" local user. That dummy user must be created and added to the table when the master user logs in for the first time.

    You can check the Opauth class in the Auth package to see how that is done.
  • Hi Harro Verton,
    Thanks for reply. But I am still confusing something that can I create the two logins using two custom drivers or not. In my case, I wanna create admin login and master login separately using their respective driver. But when I add two drivers settings in app>config>auth.php, every login (master, admin) trying to log in using the default drivers (the first one). I don't want that. I want admin to login using admin custom driver that I've created for admin and so master. In docs, I've read this one (http://fuelphp.com/docs/packages/auth/types/login.html#/method_set_config) and wrote it for changing the default driver in admin login. But it seems doesn't work. Am I do something wrong for setting the default driver?

    Admin table is like that:
    admin_name
    admin_password

    Master table is like that:
    hotel_id
    master_name
    master_password

    Admin create master accounts and hotels. Then master login using admin created hotel_id, master_name and master_password. 
  • HarroHarro
    Accepted Answer
    As I already said, if you have two SEPARATE logins, you can not use this system.

    Multiple driver support is designed for a single login towards multiple backends that may contain the same user, for example: first try the corporate Active Directory, next try the admin's LDAP server, and finally try a local account using SimpleAuth. This all happens with the same userid and password, and the first match gets it.

    It is not designed for what you have in mind.

    If you have two login pages, one for admin's and one for masters, you can use Auth with a manual config. Do not define any driver in the config file, but forge an Auth instance when a user wants to login, and pass the driver to it in a custom config array for the login being performed.

    This way you load Auth with either the master login driver or the admin login driver, but never with both.

    Note that if you do, you need to store the backend used in the session, because you need to manually forge the Auth instance on every page request before you call Auth::check(), because that will re-login the user based on the user-id stored in the session, and it needs to do that against the correct backend.

    In all, I think you are making this very complicated for yourself.
  • Thank you very much Harro Verton. You gave me a clear point. Now, I know what I should do. 

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion