public function mfaDeviceCodeValidate($iUserId, $sCode)
    {
        //  Get the user's secret
        $oSecret = $this->mfaDeviceSecretGet($iUserId);

        if (!$oSecret) {
            $this->setError('Invalid User');
            return false;
        }

        //  Has the code been used before?
        $oDb = Factory::service('Database');
        $oDb->where('secret_id', $oSecret->id);
        $oDb->where('code', $sCode);

        if ($oDb->count_all_results(NAILS_DB_PREFIX . 'user_auth_two_factor_device_code')) {
            $this->setError('Code has already been used.');
            return false;
        }

        //  Tidy up codes so that they only contain digits
        $sCode = preg_replace('/[^\d]/', '', $sCode);

        //  New instance of the authenticator
        $oGoogleAuth = new GoogleAuthenticator();
        $checkCode   = $oGoogleAuth->checkCode($oSecret->secret, $sCode);

        if ($checkCode) {

            //  Log the code so it can't be used again
            $oDb->set('secret_id', $oSecret->id);
            $oDb->set('code', $sCode);
            $oDb->set('used', 'NOW()', false);

            $oDb->insert(NAILS_DB_PREFIX . 'user_auth_two_factor_device_code');

            return true;

        } else {
            return false;
        }
    }