---
title: "How to Create a User Account in Joomla with PHP - Joomla"
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/joomla/tutorials/create-user-account-php"
date: "2026-05-01T11:23:11+00:00"
language: "en-GB"
---

[ Home ](https://www.tassos.gr/index.php?option=com_content&view=category&layout=blog&id=24&Itemid=1088) / [ Joomla ](https://www.tassos.gr/index.php?option=com_content&view=category&id=91) / [ Tutorials ](https://www.tassos.gr/index.php?option=com_content&view=category&id=92)

#  How to Create a User Account in Joomla with PHP

Heads up! This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.

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 Feb 26th 2026 15:02

## Schema

```json
{
    "@context": "https://schema.org",
    "@type": "BreadcrumbList",
    "itemListElement": [
        {
            "@type": "ListItem",
            "position": 1,
            "name": "Home",
            "item": "https://www.tassos.gr"
        },
        {
            "@type": "ListItem",
            "position": 2,
            "name": "Home",
            "item": "https://www.tassos.gr/docs"
        },
        {
            "@type": "ListItem",
            "position": 3,
            "name": "Joomla",
            "item": "https://www.tassos.gr/docs/joomla"
        },
        {
            "@type": "ListItem",
            "position": 4,
            "name": "Tutorials",
            "item": "https://www.tassos.gr/docs/joomla/tutorials"
        },
        {
            "@type": "ListItem",
            "position": 5,
            "name": "How to Create a User Account in Joomla with PHP",
            "item": "https://www.tassos.gr/docs/joomla/tutorials/create-user-account-php"
        }
    ]
}
```

```json
{
    "@context": "https://schema.org",
    "@type": "Article",
    "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "https://www.tassos.gr/docs/joomla/tutorials/create-user-account-php"
    },
    "headline": "How to Create a User Account in Joomla with PHP",
    "image": {
        "@type": "ImageObject",
        "url": "https://www.tassos.gr/"
    },
    "publisher": {
        "@type": "Organization",
        "name": "Tassos",
        "logo": {
            "@type": "ImageObject",
            "url": "https://www.tassos.gr/https://www.tassos.gr/media/brand/logo-text.png"
        }
    },
    "author": {
        "@type": "Person",
        "name": "Tassos Marinos",
        "url": "https://www.tassos.gr/docs/joomla/tutorials/create-user-account-php"
    },
    "datePublished": "2024-11-28T09:50:38+02:00",
    "dateCreated": "2024-11-28T09:50:38+02:00",
    "dateModified": "2026-02-26T15:29:18+02:00"
}
```
