benedmunds / CodeIgniter-Ion-Auth

Simple and Lightweight Auth System for CodeIgniter
http://benedmunds.com/ion_auth/
MIT License
2.35k stars 1.14k forks source link

Error in recheckTimer #1542

Closed PedroRuiz closed 2 years ago

PedroRuiz commented 2 years ago

What CodeIgniter version are you using? v4

What PHP version are you using? PHP 8.0.13 (cli) (built: Nov 22 2021 09:50:24) ( NTS ) Copyright (c) The PHP Group Zend Engine v4.0.13, Copyright (c) Zend Technologies with Zend OPcache v8.0.13, Copyright (c), by Zend Technologies with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans

Post your Ion Auth config below

<?php namespace Config;

class IonAuth extends \IonAuth\Config\IonAuth
{
    // Gaudeamus specific config
    /*
     |
     | -------------------------------------------------------------------------
     | Aonfigured by Pedro Ruiz Hidalgo 2021-12-13
     | -------------------------------------------------------------------------
     | Authentication options.
     | -------------------------------------------------------------------------
     | maximumLoginAttempts:    This maximum is not enforced by the library, but is used by
     |                          is_max_login_attempts_exceeded().
     |                          The controller should check this function and act appropriately.
     |                          If this variable set to 0, there is no maximum.
     | minPasswordLength:       This minimum is not enforced directly by the library.
     |                          The controller should define a validation rule to enforce it.
     |                          See the Auth controller for an example implementation.
     |
     | The library will fail for empty password or password size above 4096 bytes.
     | This is an arbitrary (long) value to protect against DOS attack.
     */
    public $siteTitle                = 'Gaudeamus';       // Site Title, example.com
    public $adminEmail               = 'apiservices@pedroruizhidalgo.es'; // Admin Email, admin@example.com
    public $defaultGroup             = 'members';           // Default group, use name
    public $adminGroup               = 'admin';             // Default administrators group, use name
    public $identity                 = 'email';             /* You can use any unique column in your table as identity column.
                                                                    IMPORTANT: If you are changing it from the default (email),
                                                                                update the UNIQUE constraint in your DB */
    public $minPasswordLength        = 8;                   // Minimum Required Length of Password (not enforced by lib - see note above)
    public $emailActivation          = false;               // Email Activation for registration
    public $manualActivation         = false;               // Manual Activation for registration
    public $rememberUsers            = true;                // Allow users to be remembered and enable auto-login
    public $userExpire               = 86500;               // How long to remember the user (seconds). Set to zero for no expiration
    public $userExtendonLogin        = false;               // Extend the users cookies every time they auto-login
    public $trackLoginAttempts       = true;                // Track the number of failed login attempts for each user or ip.
    public $trackLoginIpAddress      = true;                // Track login attempts by IP Address, if false will track based on identity. (Default: true)
    public $maximumLoginAttempts     = 3;                   // The maximum number of failed login attempts.
    public $lockoutTime              = 600;                 /* The number of seconds to lockout an account due to exceeded attempts
                                                                    You should not use a value below 60 (1 minute) */
    public $forgotPasswordExpiration = 1800;                /* The number of seconds after which a forgot password request will expire. If set to 0, forgot password requests will not expire.
                                                                    30 minutes to 1 hour are good values (enough for a user to receive the email and reset its password)
                                                                    You should not set a value too high, as it would be a security issue! */
    public $recheckTimer             = 15;                   /* The number of seconds after which the session is checked again against database to see if the user still exists and is active.
                                                                    Leave 0 if you don't want session recheck. if you really think you need to recheck the session against database, we would
                                                                    recommend a higher value, as this would affect performance */

    /**
     * Cookie options.
     * rememberCookieName Default: remember_code
     *
     * @var string
     */
    public $rememberCookieName = 'remember_code';

    /*
     | -------------------------------------------------------------------------
     | Email options.
     | -------------------------------------------------------------------------
     | emailConfig:
     |    'file' = Use the default CI config or use from a config file
     |    array  = Manually set your email config settings
     */
    public $useCiEmail  = true; // Send Email using the builtin CI email class, if false it will return the code and the identity
    public $emailConfig = [
        'mailType' => 'html',
    ];

    /**
     * Email templates.
     * Folder where email templates are stored.
     * Default: IonAuth\\Views\\auth\\email\\
     *
     * @var string
     */
    public $emailTemplates = 'Views\\auth\\email\\';

    /**
     * -------------------------------------------------------------------------
     * Activate Account Email Template
     * -------------------------------------------------------------------------
     * Default: activate.tpl.php
     *
     * @var string
     */
    public $emailActivate = 'activate.tpl.php';

    /**
     * -------------------------------------------------------------------------
     * Forgot Password Email Template
     * -------------------------------------------------------------------------
     * Default: forgot_password.tpl.php
     *
     * @var string
     */
    public $emailForgotPassword = 'forgot_password.tpl.php';

    /**
     * Specifies the views that are used to display the
     * errors and messages.
     *
     * @var array
     */
    public $templates = [

        // templates for errors cf : https://bcit-ci.github.io/CodeIgniter4/libraries/validation.html#configuration
        'errors'   => [
            'list' => 'list',
        ],

        // templates for messages
        'messages' => [
            'list'   => 'IonAuth\Views\Messages\list',
            'single' => 'IonAuth\Views\Messages\single',
        ],
    ];
}

Describe the bug When I set $recheckTimer equal than not zero, ex. 15, I got this:

FCPATH/vendor/benedmunds/codeigniter-ion-auth/Models/IonAuthModel.php at line 983

976         $recheck = (null !== $this->config->recheckTimer) ? $this->config->recheckTimer : 0;
977 
978         if ($recheck !== 0)
979         {
980             $lastLogin = $this->session->get('last_check');
981             if ($lastLogin + $recheck < time())
982             {
983                 $query = $this->db->select('id')
984                                   ->where([
985                                       $this->identityColumn => $this->session->get('identity'),
986                                       'active'              => '1',
987                                   ])
988                                   ->limit(1)
989                                   ->orderBy('id', 'desc')
990                                   ->get($this->tables['users']);

Expected behavior I hope this recheck with no errors, if it is possible.

benedmunds commented 2 years ago

Hey, I think I lost something in the formatting here. What error did you get?

PedroRuiz commented 2 years ago

I got this: Error Call to undefined method CodeIgniter\Database\MySQLi\Connection::select()

I think that you forgot to declare 'logged_in' trigger, do you?

benedmunds commented 2 years ago

That’s pretty weird that it would fail on the DB select call…. Is the DB class loaded here if you var_dump $this->db?

PedroRuiz commented 2 years ago

I apologize for delay. Sure, I've loaded the class. Look:

object(CodeIgniter\Database\MySQLi\Connection)[79] public 'DBDriver' => string 'MySQLi' (length=6) public 'deleteHack' => boolean true public 'escapeChar' => string '`' (length=1) public 'mysqli' => null public 'resultMode' => int 0 protected 'DSN' => string '' (length=0) protected 'port' => int 3306 protected 'hostname' => string '' (length=19) protected 'username' => string ****' (length=17) protected 'password' => string '' (length=12) protected 'database' => string '**' (length=17) protected 'subdriver' => null protected 'DBPrefix' => string '' (length=0) protected 'pConnect' => boolean false protected 'DBDebug' => boolean true protected 'charset' => string 'utf8' (length=4) protected 'DBCollat' => string 'utf8_general_ci' (length=15) protected 'swapPre' => string '' (length=0) protected 'encrypt' => boolean false protected 'compress' => boolean false protected 'strictOn' => boolean false protected 'failover' => array (size=0) empty protected 'lastQuery' => null public 'connID' => boolean false public 'resultID' => boolean false public 'protectIdentifiers' => boolean true protected 'reservedIdentifiers' => array (size=1) 0 => string '*' (length=1) public 'likeEscapeStr' => string ' ESCAPE '%s' ' (length=13) public 'likeEscapeChar' => string '!' (length=1) protected 'pregEscapeChar' => array (size=0) empty public 'dataCache' => array (size=0) empty protected 'connectTime' => null protected 'connectDuration' => null protected 'pretend' => boolean false public 'transEnabled' => boolean true public 'transStrict' => boolean true protected 'transDepth' => int 0 protected 'transStatus' => boolean true protected 'transFailure' => boolean false protected 'aliasedTables' => array (size=0) empty protected 'queryClass' => string 'CodeIgniter\Database\Query' (length=26)

Best regards!

benedmunds commented 2 years ago

That's pretty odd. I'm probably not going to have time to research this for the next week.

@bvrignaud would you have time to look at this?

PedroRuiz commented 2 years ago

Sorry for the delay, the covid, it almost made me shutdown

benedmunds commented 2 years ago

Hey Pedro,

Hope you’re feeling well! Did you find a solution to this issue?

PedroRuiz commented 2 years ago

No. Not at all. Your work is very simple to use an very hard to modify for me. Sorry man.

⁣-- Pedro Ruiz Hidalgo @pedroruizhidalg Desarrollo de sistemas de información Seguridad Informática

La Información incluida en el presente correo electrónico es SECRETO PROFESIONAL Y CONFIDENCIAL, siendo para el uso exclusivo del destinatario arriba mencionado. Si usted no es el destinatario del mensaje o ha recibido esta comunicación por error le informo que está totalmente prohibida cualquier divulgación, distribución o reproducción de esta comunicación, le ruego que me lo notifique inmediatamente y me devuelva el mensaje original a la dirección arriba mencionada.

Gracias.

The information contained in this e-mail is LEGALLY PRIVILEDGED AND CONFIDENTIAL and is intended only for the use of the addressee named above. If the reader of this message is not the intended recipient or have received this communication in error, please be aware that any dissemination, distribution or duplication of this communication is strictly prohibited, and please notify me immediately and return the original message to me at the address above.

Thank you​

En 4 ene. 2022 15:53, en 15:53, Ben Edmunds @.***> escribió:

Hey Pedro,

Hope you’re feeling well! Did you find a solution to this issue?

-- Reply to this email directly or view it on GitHub: https://github.com/benedmunds/CodeIgniter-Ion-Auth/issues/1542#issuecomment-1004877061 You are receiving this because you modified the open/close state.

Message ID: @.***>

cacsa commented 11 months ago

Hello all,

Was this ever fixed? I am experiencing the same issue.

Call to undefined method CodeIgniter\Database\MySQLi\Connection::select VENDORPATH/benedmunds/codeigniter-ion-auth/Models/IonAuthModel.php on line 983. VENDORPATH/benedmunds/codeigniter-ion-auth/Libraries/IonAuth.php(445): IonAuth\Models\IonAuthModel->recheckSession()

PedroRuiz commented 11 months ago

I didn't. Sorry.

⁣-- Pedro Ruiz Hidalgo @pedroruizhidalg Desarrollo de sistemas de información Seguridad Informática

La Información incluida en el presente correo electrónico es SECRETO PROFESIONAL Y CONFIDENCIAL, siendo para el uso exclusivo del destinatario arriba mencionado. Si usted no es el destinatario del mensaje o ha recibido esta comunicación por error le informo que está totalmente prohibida cualquier divulgación, distribución o reproducción de esta comunicación, le ruego que me lo notifique inmediatamente y me devuelva el mensaje original a la dirección arriba mencionada.

Gracias.

The information contained in this e-mail is LEGALLY PRIVILEDGED AND CONFIDENTIAL and is intended only for the use of the addressee named above. If the reader of this message is not the intended recipient or have received this communication in error, please be aware that any dissemination, distribution or duplication of this communication is strictly prohibited, and please notify me immediately and return the original message to me at the address above.

Thank you​

En 25 ago. 2023 0:03, en 0:03, cacsa @.***> escribió:

Hello all,

Was this ever fixed? I am experiencing the same issue.

Call to undefined method CodeIgniter\Database\MySQLi\Connection::select VENDORPATH/benedmunds/codeigniter-ion-auth/Models/IonAuthModel.php on line 983. VENDORPATH/benedmunds/codeigniter-ion-auth/Libraries/IonAuth.php(445): IonAuth\Models\IonAuthModel->recheckSession()

-- Reply to this email directly or view it on GitHub: https://github.com/benedmunds/CodeIgniter-Ion-Auth/issues/1542#issuecomment-1692474418 You are receiving this because you modified the open/close state.

Message ID: @.***>