public function mfaDeviceSecretValidate($iUserId, $sSecret, $iCode)
    {
        //  Tidy up codes so that they only contain digits
        $sCode = preg_replace('/[^\d]/', '', $iCode);

        //  New instance of the authenticator
        $oGoogleAuth = new GoogleAuthenticator();

        if ($oGoogleAuth->checkCode($sSecret, $sCode)) {

            $oDb      = Factory::service('Database');
            $oEncrypt = Factory::service('Encrypt');

            $oDb->set('user_id', $iUserId);
            $oDb->set('secret', $oEncrypt->encode($sSecret, APP_PRIVATE_KEY));
            $oDb->set('created', 'NOW()', false);

            if ($oDb->insert(NAILS_DB_PREFIX . 'user_auth_two_factor_device_secret')) {

                $iSecretId = $oDb->insert_id();
                $oNow      = Factory::factory('DateTime');

                $oDb->set('secret_id', $iSecretId);
                $oDb->set('code', $sCode);
                $oDb->set('used', $oNow->format('Y-m-d H:i:s'));
                $oDb->insert(NAILS_DB_PREFIX . 'user_auth_two_factor_device_code');

                return true;

            } else {
                $this->setError('Could not save secret.');
                return false;
            }

        } else {
            $this->setError('Codes did not validate.');
            return false;
        }
    }