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),
        ];
    }
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),
        ];
    }
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 ) , ] ; }
Generates a MFA Device Secret

@param  int    $iUserId         The user ID to generate for
@param  string $sExistingSecret The existing secret to use instead of generating a new one

@return boolean|array
Generates a MFA Device Secret