cakephpcakephp-2.1

cakephp admin login as another user without using password


i am creating a cakephp application that should allow admin to login as any user in the site without knowing the password. Basically if admin wants to login as a manager, he can simply click a button to login as a manager.

thank you


Solution

  • I call this user-switching. I implemented this using my DirectAuth: https://github.com/dereuromark/cakephp-tools/blob/cake2/Controller/Component/Auth/DirectAuthenticate.php

    But you can also simply

    a) login as admin

    b) have a form with all users to select the one you want to switch to

    c) switch via POST, read the user + $this->Auth->login($userData)

    login() with data passed will overwrite the current session data and therefore automatically log you in as this user. just make sure that only the admin role can access the switch action.

    side notes: