PHPGangsta_GoogleAuthenticator::getQRCodeGoogleUrl PHP Method

getQRCodeGoogleUrl() public method

Get QR-Code URL for image, from google charts.
public getQRCodeGoogleUrl ( string $name, string $secret, string $title = null, array $params = [] ) : string
$name string
$secret string
$title string
$params array
return string
    public function getQRCodeGoogleUrl($name, $secret, $title = null, $params = array())
    {
        $width = !empty($params['width']) && (int) $params['width'] > 0 ? (int) $params['width'] : 200;
        $height = !empty($params['height']) && (int) $params['height'] > 0 ? (int) $params['height'] : 200;
        $level = !empty($params['level']) && array_search($params['level'], array('L', 'M', 'Q', 'H')) !== false ? $params['level'] : 'M';
        $urlencoded = urlencode('otpauth://totp/' . $name . '?secret=' . $secret . '');
        if (isset($title)) {
            $urlencoded .= urlencode('&issuer=' . urlencode($title));
        }
        return 'https://chart.googleapis.com/chart?chs=' . $width . 'x' . $height . '&chld=' . $level . '|0&cht=qr&chl=' . $urlencoded . '';
    }

Usage Example

Example #1
0
 public function display()
 {
     include_once $this->root_path . 'libraries/twofactor/googleAuthenticator.class.php';
     $ga = new PHPGangsta_GoogleAuthenticator();
     $secret = $ga->createSecret();
     $this->tpl->assign_vars(array('TWOFACTOR_KEY' => $secret, 'TWOFACTOR_QR' => $ga->getQRCodeGoogleUrl(str_replace(' ', '_', 'EQdkpPlus ' . $this->config->get('guildtag')), $secret), 'TWOFACTOR_KEY_ENCR' => rawurlencode(register('encrypt')->encrypt($secret))));
     $this->core->set_vars(array('page_title' => "", 'header_format' => "simple", 'template_file' => 'twofactor_init.html', 'display' => true));
 }
All Usage Examples Of PHPGangsta_GoogleAuthenticator::getQRCodeGoogleUrl