---
title: "How to Create a User Account in Joomla with PHP - General"
description: "Below is a snippet on how to create a new Joomla! user account.  use Joomla\CMS\User\User; use Joomla\CMS\User\UserHelper; use Joomla\CMS\Plugin\P"
url: "https://www.tassos.gr/docs/common/tutorials/create-user-account-php"
date: "2026-11-22T14:27:59+00:00"
language: "en-GB"
---

[ Home ](https://www.tassos.gr/docs) / [ General ](https://www.tassos.gr/docs/common) / [ Joomla tutorials ](https://www.tassos.gr/docs/common/tutorials)

#  How to Create a User Account in Joomla with PHP

Below is a snippet on how to create a new Joomla! user account.

 ```

use Joomla\CMS\User\User;
use Joomla\CMS\User\UserHelper;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\Application\ApplicationHelper;
use Joomla\CMS\String\PunycodeHelper;

/**
 * Helper method to create a Joomla! User account
 *
 * @param   String  $username           The account's username
 * @param   String  $name               The account's name
 * @param   String  $email              The account's email address
 * @param   String  $password           The account's password
 * @param   Array   $groups             Comma separated Joomla! User Groups. Defaults to 2 = Registered.
 * @param   Bool    $activate           If set to true, the account will be activated without a confirmation e-mail.
 *
 * @throws  Exception
 * @return  Mixed   Object on success
 */
function addJoomlaUser($username, $name, $email, $password, $groups, $activate = false)
{
    $data = [
        'name'      => $name,
        'username'  => $username,
        'password'  => $password,
        'password2' => $password,
        'email'     => PunycodeHelper::emailToPunycode($email),
        'groups'    => explode(',', $groups),
    ];

    if (!$activate)
    {
        $hash = ApplicationHelper::getHash(UserHelper::genRandomPassword());
        $data['activation'] = $hash;
        $data['block'] = 1;
    }

    // Load the users plugin group.
    PluginHelper::importPlugin('user');

    $user = new User();

    if (!$user->bind($data))
    {
        throw new \Exception($user->getError());
    }

    if (!$user->save())
    {
        throw new \Exception($user->getError());
    }

    return $user;
}

// Create an inactive account. User will need to click on the confirmation e-mail.
$new_user = addJoomlaUser('johndoe', 'John Doe', 'john@doe.com', '123456', '2');

// Create an active user account. No confirmation e-mail will be sent.
$new_user = addJoomlaUser('johndoe', 'John Doe', 'john@doe.com', '123456', '2', true);
```

 Last updated on Nov 20th 2026 13:11
