public function mfaDeviceSecretGenerate($iUserId, $sExistingSecret = null)
    {
        //  Get an identifier for the user
        $oUserModel = Factory::model('User', 'nails/module-auth');
        $oUser      = $oUserModel->getById($iUserId);

        if (!$oUser) {
            $this->setError('User does not exist.');
            return false;
        }

        $oGoogleAuth = new GoogleAuthenticator();

        //  Generate the secret
        if (empty($sExistingSecret)) {
            $sSecret = $oGoogleAuth->generateSecret();
        } else {
            $sSecret = $sExistingSecret;
        }

        //  Get the hostname
        $sHostname = Functions::getDomainFromUrl(BASE_URL);

        //  User identifier
        $sUsername = $oUser->username;
        $sUsername = empty($sUsername) ? preg_replace('/[^a-z]/', '', strtolower($oUser->first_name . $oUser->last_name)) : $sUsername;
        $sUsername = empty($sUsername) ? preg_replace('/[^a-z]/', '', strtolower($oUser->email)) : $sUsername;

        return [
            'secret' => $sSecret,
            'url'    => $oGoogleAuth->getUrl($sUsername, $sHostname, $sSecret),
        ];
    }