setLabel($account['account_email']); // $otp->setLabel(rawurlencode(System::get_platform_name())); $otp->setIssuer(rawurlencode(System::get_platform_name())); $mySecret = trim(Base32::encodeUpper(random_bytes(32)), '='); $otp = TOTP::create($mySecret); q("UPDATE account set account_external = '%s' where account_id = %d", dbesc($otp->getSecret()), intval($account['account_id']) ); $account['account_external'] = $otp->getSecret(); } $otp = TOTP::create($account['account_external']); $otp->setLabel($account['account_email']); $otp->setIssuer(rawurlencode(System::get_platform_name())); $uri = $otp->getProvisioningUri(); return replace_macros(get_markup_template('totp_setup.tpl'), [ '$form_security_token' => get_form_security_token("settings_mfa"), '$title' => t('Account Multi-Factor Authentication'), '$secret_text' => t('This is your generated secret. It may be used in some cases if the QR image cannot be read. Please store it in a safe place.'), '$test_title' => t('Please enter the code from your authenticator app'), '$test_title_sub' => t('You will only be able to enable MFA if the test passes'), '$qrcode' => (new QRCode())->render($uri), '$uri' => $uri, '$secret' => ($account['account_external'] ?? ''), '$test_pass' => t("Congratulations, the provided code was correct"), '$test_fail' => t("Incorrect code"), '$enable_mfa' => [ 'enable_mfa', t('Enable Multi-Factor Authentication'), AConfig::Get($account['account_id'], 'system', 'mfa_enabled'), t('Logging in will require you to be in possession of your smartphone'), [t('No'), t('Yes')] ], '$password' => ['password', t('Your account password'), '', t('Required')], '$submit' => t('Submit'), '$test' => t('Test') ] ); } }