public function mfaTokenGenerate($iUserId)
    {
        $oPasswordModel = Factory::model('UserPassword', 'nails/module-auth');
        $oNow           = Factory::factory('DateTime');
        $oInput         = Factory::service('Input');
        $oDb            = Factory::service('Database');

        $sSalt    = $oPasswordModel->salt();
        $sIp      = $oInput->ipAddress();
        $sCreated = $oNow->format('Y-m-d H:i:s');
        $sExpires = $oNow->add(new \DateInterval('PT10M'))->format('Y-m-d H:i:s');
        $aToken   = [
            'token' => sha1(sha1(APP_PRIVATE_KEY . $iUserId . $sCreated . $sExpires . $sIp) . $sSalt),
            'salt'  => md5($sSalt),
        ];

        //  Add this to the DB
        $oDb->set('user_id', $iUserId);
        $oDb->set('token', $aToken['token']);
        $oDb->set('salt', $aToken['salt']);
        $oDb->set('created', $sCreated);
        $oDb->set('expires', $sExpires);
        $oDb->set('ip', $sIp);

        if ($oDb->insert(NAILS_DB_PREFIX . 'user_auth_two_factor_token')) {
            $aToken['id'] = $oDb->insert_id();
            return $aToken;
        } else {
            $error = lang('auth_twofactor_token_could_not_generate');
            $this->setError($error);
            return false;
        }
    }
public function mfaTokenGenerate($iUserId)
    {
        $oPasswordModel = Factory::model('UserPassword', 'nails/module-auth');
        $oNow           = Factory::factory('DateTime');
        $oInput         = Factory::service('Input');
        $oDb            = Factory::service('Database');

        $sSalt    = $oPasswordModel->salt();
        $sIp      = $oInput->ipAddress();
        $sCreated = $oNow->format('Y-m-d H:i:s');
        $sExpires = $oNow->add(new \DateInterval('PT10M'))->format('Y-m-d H:i:s');
        $aToken   = [
            'token' => sha1(sha1(APP_PRIVATE_KEY . $iUserId . $sCreated . $sExpires . $sIp) . $sSalt),
            'salt'  => md5($sSalt),
        ];

        //  Add this to the DB
        $oDb->set('user_id', $iUserId);
        $oDb->set('token', $aToken['token']);
        $oDb->set('salt', $aToken['salt']);
        $oDb->set('created', $sCreated);
        $oDb->set('expires', $sExpires);
        $oDb->set('ip', $sIp);

        if ($oDb->insert(NAILS_DB_PREFIX . 'user_auth_two_factor_token')) {
            $aToken['id'] = $oDb->insert_id();
            return $aToken;
        } else {
            $error = lang('auth_twofactor_token_could_not_generate');
            $this->setError($error);
            return false;
        }
    }
public function mfaTokenGenerate ( $ iUserId ) { $ oPasswordModel = Factory :: model ( 'UserPassword' , 'nails/module-auth' ) ; $ oNow = Factory :: factory ( 'DateTime' ) ; $ oInput = Factory :: service ( 'Input' ) ; $ oDb = Factory :: service ( 'Database' ) ; $ sSalt = $ oPasswordModel -> salt ( ) ; $ sIp = $ oInput -> ipAddress ( ) ; $ sCreated = $ oNow -> format ( 'Y-m-d H:i:s' ) ; $ sExpires = $ oNow -> add ( new \ DateInterval ( 'PT10M' ) ) -> format ( 'Y-m-d H:i:s' ) ; $ aToken = [ 'token' => sha1 ( sha1 ( APP_PRIVATE_KEY . $ iUserId . $ sCreated . $ sExpires . $ sIp ) . $ sSalt ) , 'salt' => md5 ( $ sSalt ) , ] ; //  Add this to the DB $ oDb -> set ( 'user_id' , $ iUserId ) ; $ oDb -> set ( 'token' , $ aToken [ 'token' ] ) ; $ oDb -> set ( 'salt' , $ aToken [ 'salt' ] ) ; $ oDb -> set ( 'created' , $ sCreated ) ; $ oDb -> set ( 'expires' , $ sExpires ) ; $ oDb -> set ( 'ip' , $ sIp ) ; if ( $ oDb -> insert ( NAILS_DB_PREFIX . 'user_auth_two_factor_token' ) ) { $ aToken [ 'id' ] = $ oDb -> insert_id ( ) ; return $ aToken ; } else { $ error = lang ( 'auth_twofactor_token_could_not_generate' ) ; $ this -> setError ( $ error ) ; return false ; } }
Generate an MFA token

@param  int $iUserId The user ID to generate the token for

@return array|false
Generate an MFA token