Alternative authentication sources in CakePHP (LDAP)

后端 未结 3 873
孤城傲影
孤城傲影 2021-02-04 18:30

I\'m working on a CakePHP project and am currently building the user authentication part of it. The problem is that my authentication information (ie: the passwords) are not sto

3条回答
  •  南旧
    南旧 (楼主)
    2021-02-04 19:14

    I was able to hack around the way Cake does it in a relatively dodgy, but probably acceptable way.

    I added a "password" field onto my users table and set everyone's password to "a" (though you could use anything).

    Then I added a custom hashing function into my model:

    function hashPasswords($data) {
        $data['User']['password'] = 'a';
        return $data;
    }
    

    And told my controller to use that model for hashing:

    $this->Auth->authenticate = ClassRegistry::init('User');
    

    This means now that cake's first step will always pass (assuming the username exists in the table). The authorize function can now do its thing and do your proper check using whatever method you'd like.

    It's basically changed the process to this:

    // The process
    1. User provides details
    2. Cake checks the database **and always returns OK**
    3. If OK, then check the custom object method
    4. If OK, return true
    

提交回复
热议问题