public function mfaQuestionSet($iUserId, $aData, $bClearOld = true)
    {
        //  Check input
        foreach ($aData as $oDatum) {
            if (empty($oDatum->question) || empty($oDatum->answer)) {
                $this->setError('Malformed question/answer data.');
                return false;
            }
        }

        //  Begin transaction
        $oDb = Factory::service('Database');
        $oDb->trans_begin();

        //  Delete old questions?
        if ($bClearOld) {
            $oDb->where('user_id', $iUserId);
            $oDb->delete(NAILS_DB_PREFIX . 'user_auth_two_factor_question');
        }

        $oPasswordModel = Factory::model('UserPassword', 'nails/module-auth');
        $oEncrypt       = Factory::service('Encrypt');

        $aQuestionData = [];
        $iCounter      = 0;
        $oNow          = Factory::factory('DateTime');
        $sDateTime     = $oNow->format('Y-m-d H:i:s');

        foreach ($aData as $oDatum) {
            $sSalt                    = $oPasswordModel->salt();
            $aQuestionData[$iCounter] = [
                'user_id'        => $iUserId,
                'salt'           => $sSalt,
                'question'       => $oEncrypt->encode($oDatum->question, APP_PRIVATE_KEY . $sSalt),
                'answer'         => sha1(sha1(strtolower($oDatum->answer)) . APP_PRIVATE_KEY . $sSalt),
                'created'        => $sDateTime,
                'last_requested' => null,
            ];
            $iCounter++;
        }

        if ($aQuestionData) {

            $oDb->insert_batch(NAILS_DB_PREFIX . 'user_auth_two_factor_question', $aQuestionData);

            if ($oDb->trans_status() !== false) {
                $oDb->trans_commit();
                return true;
            } else {
                $oDb->trans_rollback();
                return false;
            }

        } else {
            $oDb->trans_rollback();
            $this->setError('No data to save.');
            return false;
        }
    }
public function mfaQuestionSet($iUserId, $aData, $bClearOld = true)
    {
        //  Check input
        foreach ($aData as $oDatum) {
            if (empty($oDatum->question) || empty($oDatum->answer)) {
                $this->setError('Malformed question/answer data.');
                return false;
            }
        }

        //  Begin transaction
        $oDb = Factory::service('Database');
        $oDb->trans_begin();

        //  Delete old questions?
        if ($bClearOld) {
            $oDb->where('user_id', $iUserId);
            $oDb->delete(NAILS_DB_PREFIX . 'user_auth_two_factor_question');
        }

        $oPasswordModel = Factory::model('UserPassword', 'nails/module-auth');
        $oEncrypt       = Factory::service('Encrypt');

        $aQuestionData = [];
        $iCounter      = 0;
        $oNow          = Factory::factory('DateTime');
        $sDateTime     = $oNow->format('Y-m-d H:i:s');

        foreach ($aData as $oDatum) {
            $sSalt                    = $oPasswordModel->salt();
            $aQuestionData[$iCounter] = [
                'user_id'        => $iUserId,
                'salt'           => $sSalt,
                'question'       => $oEncrypt->encode($oDatum->question, APP_PRIVATE_KEY . $sSalt),
                'answer'         => sha1(sha1(strtolower($oDatum->answer)) . APP_PRIVATE_KEY . $sSalt),
                'created'        => $sDateTime,
                'last_requested' => null,
            ];
            $iCounter++;
        }

        if ($aQuestionData) {

            $oDb->insert_batch(NAILS_DB_PREFIX . 'user_auth_two_factor_question', $aQuestionData);

            if ($oDb->trans_status() !== false) {
                $oDb->trans_commit();
                return true;
            } else {
                $oDb->trans_rollback();
                return false;
            }

        } else {
            $oDb->trans_rollback();
            $this->setError('No data to save.');
            return false;
        }
    }
public function mfaQuestionSet ( $ iUserId , $ aData , $ bClearOld = true ) { //  Check input foreach ( $ aData as $ oDatum ) { if ( empty ( $ oDatum -> question ) || empty ( $ oDatum -> answer ) ) { $ this -> setError ( 'Malformed question/answer data.' ) ; return false ; } } //  Begin transaction $ oDb = Factory :: service ( 'Database' ) ; $ oDb -> trans_begin ( ) ; //  Delete old questions? if ( $ bClearOld ) { $ oDb -> where ( 'user_id' , $ iUserId ) ; $ oDb -> delete ( NAILS_DB_PREFIX . 'user_auth_two_factor_question' ) ; } $ oPasswordModel = Factory :: model ( 'UserPassword' , 'nails/module-auth' ) ; $ oEncrypt = Factory :: service ( 'Encrypt' ) ; $ aQuestionData = [ ] ; $ iCounter = 0 ; $ oNow = Factory :: factory ( 'DateTime' ) ; $ sDateTime = $ oNow -> format ( 'Y-m-d H:i:s' ) ; foreach ( $ aData as $ oDatum ) { $ sSalt = $ oPasswordModel -> salt ( ) ; $ aQuestionData [ $ iCounter ] = [ 'user_id' => $ iUserId , 'salt' => $ sSalt , 'question' => $ oEncrypt -> encode ( $ oDatum -> question , APP_PRIVATE_KEY . $ sSalt ) , 'answer' => sha1 ( sha1 ( strtolower ( $ oDatum -> answer ) ) . APP_PRIVATE_KEY . $ sSalt ) , 'created' => $ sDateTime , 'last_requested' => null , ] ; $ iCounter ++ ; } if ( $ aQuestionData ) { $ oDb -> insert_batch ( NAILS_DB_PREFIX . 'user_auth_two_factor_question' , $ aQuestionData ) ; if ( $ oDb -> trans_status ( ) !== false ) { $ oDb -> trans_commit ( ) ; return true ; } else { $ oDb -> trans_rollback ( ) ; return false ; } } else { $ oDb -> trans_rollback ( ) ; $ this -> setError ( 'No data to save.' ) ; return false ; } }
Sets MFA questions for a user

@param  int     $iUserId   The user's ID
@param  array   $aData     An array of question and answers
@param  boolean $bClearOld Whether or not to clear old questions

@return boolean
Sets MFA questions for a user