Skip to content

Instantly share code, notes, and snippets.

@medigeek
Created April 9, 2018 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save medigeek/28a047be0d0d527a95769130a6faf559 to your computer and use it in GitHub Desktop.
Save medigeek/28a047be0d0d527a95769130a6faf559 to your computer and use it in GitHub Desktop.
Joomla 3.x - Disable two factor authentication plugin, clear otpKey and otep values for all Super Users
<?php
/* This script disables Joomla!'s two factor authentication
* plugin and clears the otpKey and otep values for Super
* Users. It allows you to login when you aren't able to
* use Google authenticator for any reason.
* Usage:
* Place it in the Joomla! 3.x root dir (where configuration.php
* and index.php are) and run it. Then login and leave the
* security key field empty.
* Warning: Use with caution. Backup before use.
*/
define('_JEXEC', 1);
define('JPATH_BASE', __DIR__);
error_reporting(E_ALL);
ini_set('display_errors', 1);
// Load system defines
if (file_exists(JPATH_BASE . '/defines.php')) { require_once JPATH_BASE . '/defines.php'; }
if (!defined('_JDEFINES')) { require_once JPATH_BASE . '/includes/defines.php'; }
require_once JPATH_LIBRARIES . '/import.legacy.php'; // Get the framework.
require_once JPATH_LIBRARIES . '/cms.php'; // Bootstrap the CMS libraries.
class Reset2FA extends JApplicationCli
{
public function execute()
{
$this->out('Initialising');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query2 = $db->getQuery(true);
//get users by group: (array of integers)
$sadminids = JAccess::getUsersByGroup(8); // 8 = Super Users
$strsadminids = implode(',', $sadminids);
$this->out(sprintf('Super User IDs: %s', $strsadminids));
$this->out('Disabling twofactorauth plugin (totp and yubikey)');
// Fields to update.
$fields = array(sprintf('%s = 0', $db->quoteName('enabled')));
// Conditions for which records should be updated.
// plg_twofactorauth_totp
// plg_twofactorauth_yubikey
$conditions = array(sprintf('%s LIKE %s', $db->quoteName('name'), $db->quote('plg_twofactorauth_%')));
$query->update($db->quoteName('#__extensions'))->set($fields)->where($conditions);
$db->setQuery($query);
$result = $db->execute();
$this->out('Disabling/clearing otpKey and otep for all Super Users');
// UPDATE 2
$fields2 = array(
$db->quoteName('otpKey') . " = ''",
$db->quoteName('otep') . " = ''",
);
// Conditions for which records should be updated.
// otpKey
// otep
$conditions2 = array(
$db->quoteName('otpKey') . " != ''",
$db->quoteName('otep') . " != ''",
sprintf('%s IN (%s)', $db->quoteName('id'), $strsadminids)
);
$query2->update($db->quoteName('#__users'))->set($fields2)->where($conditions2);
$db->setQuery($query2);
$result2 = $db->execute();
$this->out('Done');
}
}
JApplicationCli::getInstance('Reset2FA')->execute();
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment