Welcome Guest, Not a member yet? Register   Sign In
Avoid using other libraries in own library
#8

First, since no-one has mentioned it yet, read the PHP manual's entry on safe password hashing: http://php.net/manual/en/faq.passwords.php

As far as an authentication library goes, at a minimum you'll need something like isLoggedIn(), login(), and logout().

In general, I would use a single controller to manage most of the authentication-related functionality, such as login, logout, and registration. Then I would probably add a simple (protected) method to MY_Controller which I could call from my other controllers when a user is required to login. This would call the authentication library's isLoggedIn() method, then redirect to the login form if the user is not logged in.

If you really want to use as little of the CI libraries as possible in your authentication library, your best bet would be to start by isolating the calls to CI's libraries in your library, usually by creating protected/private methods in your library which interface with the CI library. Once you've done that, you can extract those methods into an adapter class, which you can inject into your authentication library's constructor as a value in the parameter array (the optional second argument to $this->load->library()). So, you would do something like this when loading your authentication library:

PHP Code:
$this->load->library('authentication_ci_adapter');
$authParams = [
    
'adapter' => $this->authentication_ci_adapter,
];
$this->load->library('authentication'$authParams); 
Reply


Messages In This Thread
RE: Avoid using other libraries in own library - by mwhitney - 08-04-2016, 06:38 AM



Theme © iAndrew 2016 - Forum software by © MyBB