public function mfaQuestionGet($iUserId)
    {
        $oDb    = Factory::service('Database');
        $oInput = Factory::service('Input');

        $oDb->where('user_id', $iUserId);
        $oDb->order_by('last_requested', 'DESC');
        $aQuestions = $oDb->get(NAILS_DB_PREFIX . 'user_auth_two_factor_question')->result();

        if (!$aQuestions) {
            $this->setError('No security questions available for this user.');
            return false;
        }

        // --------------------------------------------------------------------------

        //  Choose a question to return
        if (count($aQuestions) == 1) {

            //  No choice, just return the lonely question
            $oOut = reset($aQuestions);

        } elseif (count($aQuestions) > 1) {

            /**
             * Has the most recently asked question been asked in the last 10 minutes?
             * If so, return that one again (to make harvesting all the user's questions
             * a little more time consuming). If not randomly choose one.
             */

            $oOut = reset($aQuestions);
            if (strtotime($oOut->last_requested) < strtotime('-10 MINS')) {
                $oOut = $aQuestions[array_rand($aQuestions)];
            }

        } else {
            $this->setError('Could not determine security question.');
            return false;
        }

        //  Decode the question
        $oEncrypt       = Factory::service('Encrypt');
        $oOut->question = $oEncrypt->decode($oOut->question, APP_PRIVATE_KEY . $oOut->salt);

        //  Update the last requested details
        $oDb->set('last_requested', 'NOW()', false);
        $oDb->set('last_requested_ip', $oInput->ipAddress());
        $oDb->where('id', $oOut->id);
        $oDb->update(NAILS_DB_PREFIX . 'user_auth_two_factor_question');

        return $oOut;
    }
public function mfaQuestionGet($iUserId)
    {
        $oDb    = Factory::service('Database');
        $oInput = Factory::service('Input');

        $oDb->where('user_id', $iUserId);
        $oDb->order_by('last_requested', 'DESC');
        $aQuestions = $oDb->get(NAILS_DB_PREFIX . 'user_auth_two_factor_question')->result();

        if (!$aQuestions) {
            $this->setError('No security questions available for this user.');
            return false;
        }

        // --------------------------------------------------------------------------

        //  Choose a question to return
        if (count($aQuestions) == 1) {

            //  No choice, just return the lonely question
            $oOut = reset($aQuestions);

        } elseif (count($aQuestions) > 1) {

            /**
             * Has the most recently asked question been asked in the last 10 minutes?
             * If so, return that one again (to make harvesting all the user's questions
             * a little more time consuming). If not randomly choose one.
             */

            $oOut = reset($aQuestions);
            if (strtotime($oOut->last_requested) < strtotime('-10 MINS')) {
                $oOut = $aQuestions[array_rand($aQuestions)];
            }

        } else {
            $this->setError('Could not determine security question.');
            return false;
        }

        //  Decode the question
        $oEncrypt       = Factory::service('Encrypt');
        $oOut->question = $oEncrypt->decode($oOut->question, APP_PRIVATE_KEY . $oOut->salt);

        //  Update the last requested details
        $oDb->set('last_requested', 'NOW()', false);
        $oDb->set('last_requested_ip', $oInput->ipAddress());
        $oDb->where('id', $oOut->id);
        $oDb->update(NAILS_DB_PREFIX . 'user_auth_two_factor_question');

        return $oOut;
    }
public function mfaQuestionGet ( $ iUserId ) { $ oDb = Factory :: service ( 'Database' ) ; $ oInput = Factory :: service ( 'Input' ) ; $ oDb -> where ( 'user_id' , $ iUserId ) ; $ oDb -> order_by ( 'last_requested' , 'DESC' ) ; $ aQuestions = $ oDb -> get ( NAILS_DB_PREFIX . 'user_auth_two_factor_question' ) -> result ( ) ; if ( ! $ aQuestions ) { $ this -> setError ( 'No security questions available for this user.' ) ; return false ; } // -------------------------------------------------------------------------- //  Choose a question to return if ( count ( $ aQuestions ) == 1 ) { //  No choice, just return the lonely question $ oOut = reset ( $ aQuestions ) ; } elseif ( count ( $ aQuestions ) > 1 ) { /**
             * Has the most recently asked question been asked in the last 10 minutes?
             * If so, return that one again (to make harvesting all the user's questions
             * a little more time consuming). If not randomly choose one.
             */ $ oOut = reset ( $ aQuestions ) ; if ( strtotime ( $ oOut -> last_requested ) < strtotime ( '-10 MINS' ) ) { $ oOut = $ aQuestions [ array_rand ( $ aQuestions ) ] ; } } else { $ this -> setError ( 'Could not determine security question.' ) ; return false ; } //  Decode the question $ oEncrypt = Factory :: service ( 'Encrypt' ) ; $ oOut -> question = $ oEncrypt -> decode ( $ oOut -> question , APP_PRIVATE_KEY . $ oOut -> salt ) ; //  Update the last requested details $ oDb -> set ( 'last_requested' , 'NOW()' , false ) ; $ oDb -> set ( 'last_requested_ip' , $ oInput -> ipAddress ( ) ) ; $ oDb -> where ( 'id' , $ oOut -> id ) ; $ oDb -> update ( NAILS_DB_PREFIX . 'user_auth_two_factor_question' ) ; return $ oOut ; }
Fetches a random MFA question for a user

@param  int $iUserId The user's ID

@return boolean|\stdClass
Fetches a random MFA question for a user