Skip to content

Instantly share code, notes, and snippets.

@EpicVoyage
Created December 10, 2017 18:48
Show Gist options
  • Save EpicVoyage/c8f9389fbad63176993170327a76ad49 to your computer and use it in GitHub Desktop.
Save EpicVoyage/c8f9389fbad63176993170327a76ad49 to your computer and use it in GitHub Desktop.
Expression Engine 2: User Creation Script
<?php
/**
* Usage: Drop in the system/ folder, then open in your browser.
*/
# Define your login details.
$user = 'epicvoyage';
$pass = 'epicvoyage';
$email = '[email protected]';
$url = 'https://www.epicvoyage.org';
# Hacks.
define('BASEPATH', true);
function get_instance() {
return true;
}
ini_set('display_errors', 1);
error_reporting(-1);
# Load the required files.
require_once('system/expressionengine/config/database.php');
require_once('system/expressionengine/libraries/Auth.php');
class import_users {
private $prefix = '';
private $sql = null;
private $auth = null;
function __construct() {
global $db;
@$this->auth = new Auth();
$this->prefix = $db['expressionengine']['dbprefix'];
# Start a database connection.
$this->sql = new mysqli($db['expressionengine']['hostname'], $db['expressionengine']['username'], $db['expressionengine']['password'], $db['expressionengine']['database']);
if ($this->sql->connect_errno) {
die('Error connecting to the database: '.mysqli_connect_error()."<br />\n");
}
}
function import($group, $user, $email, $pass) {
# Load the EE Auth class and hash the password.
$hash = $this->auth->hash_password($pass);
# And... create an account.
$result = $this->sql->query(
'INSERT INTO `'.$this->prefix.'members` (`group_id`, `username`, `screen_name`, `password`, `email`, `salt`, `unique_id`, `language`, `timezone`)
VALUES ('.intval($group).', "'.$this->sql->escape_string($user).
'", "'.$this->sql->escape_string($user).
'", "'.$this->sql->escape_string($hash['password']).
'", "'.$this->sql->escape_string($email).
'", "'.$this->sql->escape_string($hash['salt']).
'", "'.mt_rand(str_repeat('1', 30) , str_repeat('9', 30)).
'", "english", "America/Chicago")'
);
if (!$result) {
echo 'Query failed: '.$this->sql->error."<br />\n";
} elseif ($this->sql->insert_id) {
echo "Success.<br />\n";
}
}
}
$import_users = new import_users();
$import_users->import(1, $user, $email, $pass);
# Redirect to the login page.
//header('Location: index.php');
# And before we close, delete ourself...
//unlink(__FILE__);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment