GENWiki

Premier IT Outsourcing and Support Services within the UK

User Tools

Site Tools


joomla:create_a_new_user_and_set_its_password
function generate_password($length = 20) {
    $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`-=~!@#$%^&*()_+,./<>?;:[]{}\|';
    $str = '';
    $max = strlen($chars) - 1;
    for ($i=0; $i < $length; $i++)
    $str .= $chars[random_int(0, $max)];
    return $str;
}
 
function CreateUser($forename,$surname, $username, $email) {
    $pass = generate_password(12);
    $data['name'] = $forename . ' ' . $surname;
    $data['username'] = $username;
    $data['email1'] = $email;
    $data['email2'] = $email;
    $data['password1'] = $pass;
    $data['password2'] = $pass;
 
    print_r($data);
 
    JFactory::getLanguage()->load('com_users');
    JModelLegacy::addIncludePath(JPATH_ROOT . '/components/com_users/models');
 
    $model = JModelLegacy::getInstance('Registration', 'UsersModel');
    return $model->register($data);
 
}
 
$fname="fred";
$sname="bloggs";
$email="fred.bloggs@genzone.net";
$uname="freddy";
 
$ret=CreateUser($fname,$sname, $uname, $email);
// $ret = false if the create user failed, otherwise will be a string "useractivate"
 
echo "Return Code ";
var_dump($ret);
echo "<br>";

This code simply creates a new user $uname with the email $email and $fname $sname as the forename and surname. Returns false if the create user failed, otherwise will be a string "useractivate" which means an activation email has been sent to the user.

/data/webs/external/dokuwiki/data/pages/joomla/create_a_new_user_and_set_its_password.txt · Last modified: 2019/05/20 10:14 by genadmin

Was this page helpful?-13+1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki