Joomla Platform  13.1
Documentation des API du framework Joomla Platform
 Tout Classes Espaces de nommage Fichiers Fonctions Variables Pages
Référence de la classe JUserHelper

Liste de tous les membres

Fonctions membres publiques statiques

static addUserToGroup ($userId, $groupId)
static getUserGroups ($userId)
static removeUserFromGroup ($userId, $groupId)
static setUserGroups ($userId, $groups)
static getProfile ($userId=0)
static activateUser ($activation)
static getUserId ($username)
static getCryptedPassword ($plaintext, $salt= '', $encryption= 'bcrypt', $show_encrypt=false)
static getSalt ($encryption= 'md5-hex', $seed= '', $plaintext= '')
static genRandomPassword ($length=16)
static invalidateCookie ($userId, $cookieName)
static clearExpiredTokens ()
static getRememberCookieData ()
static getShortHashedUserAgent ()

Fonctions membres protégées statiques

static _toAPRMD5 ($value, $count)

Fonctions membres privées statiques

static _bin ($hex)

Description détaillée

Définition à la ligne 25 du fichier helper.php.


Documentation des fonctions membres

static JUserHelper::_bin (   $hex)
staticprivate

Converts hexadecimal string to binary data.

Paramètres:
string$hexHex data.
Renvoie:
string Binary data.
Depuis:
11.1

Définition à la ligne 666 du fichier helper.php.

{
$bin = '';
$length = strlen($hex);
for ($i = 0; $i < $length; $i += 2)
{
$tmp = sscanf(substr($hex, $i, 2), '%x');
$bin .= chr(array_shift($tmp));
}
return $bin;
}
static JUserHelper::_toAPRMD5 (   $value,
  $count 
)
staticprotected

Converts to allowed 64 characters for APRMD5 passwords.

Paramètres:
string$valueThe value to convert.
integer$countThe number of characters to convert.
Renvoie:
string $value converted to the 64 MD5 characters.
Depuis:
11.1

Définition à la ligne 641 du fichier helper.php.

{
/* 64 characters that are valid for APRMD5 passwords. */
$APRMD5 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$aprmd5 = '';
$count = abs($count);
while (--$count)
{
$aprmd5 .= $APRMD5[$value & 0x3f];
$value >>= 6;
}
return $aprmd5;
}
static JUserHelper::activateUser (   $activation)
static

Method to activate a user

Paramètres:
string$activationActivation string
Renvoie:
boolean True on success
Depuis:
11.1

Définition à la ligne 239 du fichier helper.php.

Références JText\_(), JLog\add(), JFactory\getDbo(), JUser\getInstance(), et JLog\WARNING.

{
// Let's get the id of the user we want to activate
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__users'))
->where($db->quoteName('activation') . ' = ' . $db->quote($activation))
->where($db->quoteName('block') . ' = 1')
->where($db->quoteName('lastvisitDate') . ' = ' . $db->quote('0000-00-00 00:00:00'));
$db->setQuery($query);
$id = (int) $db->loadResult();
// Is it a valid user to activate?
if ($id)
{
$user = JUser::getInstance((int) $id);
$user->set('block', '0');
$user->set('activation', '');
// Time to take care of business.... store the user.
if (!$user->save())
{
JLog::add($user->getError(), JLog::WARNING, 'jerror');
return false;
}
}
else
{
JLog::add(JText::_('JLIB_USER_ERROR_UNABLE_TO_FIND_USER'), JLog::WARNING, 'jerror');
return false;
}
return true;
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::addUserToGroup (   $userId,
  $groupId 
)
static

Method to add a user to a group.

Paramètres:
integer$userIdThe id of the user.
integer$groupIdThe id of the group.
Renvoie:
boolean True on success
Depuis:
11.1
Exceptions:
RuntimeException

Définition à la ligne 38 du fichier helper.php.

Références JFactory\getDbo(), et JFactory\getUser().

{
// Get the user object.
$user = new JUser((int) $userId);
// Add the user to the group if necessary.
if (!in_array($groupId, $user->groups))
{
// Get the title of the group.
$query = $db->getQuery(true)
->select($db->quoteName('title'))
->from($db->quoteName('#__usergroups'))
->where($db->quoteName('id') . ' = ' . (int) $groupId);
$db->setQuery($query);
$title = $db->loadResult();
// If the group does not exist, return an exception.
if (!$title)
{
throw new RuntimeException('Access Usergroup Invalid');
}
// Add the group data to the user object.
$user->groups[$title] = $groupId;
// Store the user object.
$user->save();
}
if (session_id())
{
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
}
return true;
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::clearExpiredTokens ( )
static

Clear all expired tokens for all users.

Renvoie:
mixed Database query result
Depuis:
3.2

Définition à la ligne 717 du fichier helper.php.

Références JFactory\getDbo().

{
$now = time();
$query = $db->getQuery(true)
->delete('#__user_keys')
->where($db->quoteName('time') . ' < ' . $db->quote($now));
return $db->setQuery($query)->execute();
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::genRandomPassword (   $length = 16)
static

Generate a random password

Paramètres:
integer$lengthLength of the password to generate
Renvoie:
string Random Password
Depuis:
11.1

Définition à la ligne 606 du fichier helper.php.

Références JCrypt\genRandomBytes().

Référencé par JUser\bind().

{
$salt = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$base = strlen($salt);
$makepass = '';
/*
* Start with a cryptographic strength random string, then convert it to
* a string with the numeric base of the salt.
* Shift the base conversion on each character so the character
* distribution is even, and randomize the start shift so it's not
* predictable.
*/
$random = JCrypt::genRandomBytes($length + 1);
$shift = ord($random[0]);
for ($i = 1; $i <= $length; ++$i)
{
$makepass .= $salt[($shift + ord($random[$i])) % $base];
$shift += ord($random[$i]);
}
return $makepass;
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JUserHelper::getCryptedPassword (   $plaintext,
  $salt = '',
  $encryption = 'bcrypt',
  $show_encrypt = false 
)
static

Formats a password using the current encryption.

Paramètres:
string$plaintextThe plaintext password to encrypt.
string$saltThe salt to use to encrypt the password. [] If not present, a new salt will be generated.
string$encryptionThe kind of password encryption to use. Defaults to md5-hex.
boolean$show_encryptSome password systems prepend the kind of encryption to the crypted password ({SHA}, etc). Defaults to false.
Renvoie:
string The encrypted password.
Depuis:
11.1
Note:
In Joomla! CMS 3.2 the default encrytion has been changed to bcrypt. When PHP 5.5 is the minimum supported version it will be changed to the PHP PASSWORD_DEFAULT constant.

Définition à la ligne 320 du fichier helper.php.

Références JText\_(), JFactory\getApplication(), et JCrypt\hasStrongPasswordSupport().

Référencé par JUser\bind().

{
if ($app->getClientId() != 2)
{
$joomlaPluginEnabled = JPluginHelper::isEnabled('user', 'joomla');
}
// The Joomla user plugin allows you to use weaker passwords if necessary.
if (!empty($joomlaPluginEnabled))
{
JPluginHelper::importPlugin('user', 'joomla');
$userPlugin = JPluginHelper::getPlugin('user', 'joomla');
$userPluginParams = new JRegistry($userPlugin->params);
PlgUserJoomla::setDefaultEncryption($userPluginParams);
}
// Not all controllers check the length, although they should to avoid DOS attacks.
// The maximum password length for bcrypt is 55:
if (strlen($plaintext) > 55)
{
$app->enqueueMessage(JText::_('JLIB_USER_ERROR_PASSWORD_TOO_LONG'), 'error');
return false;
}
// Get the salt to use.
if (empty($salt))
{
$salt = self::getSalt($encryption, $salt, $plaintext);
}
// Encrypt the password.
switch ($encryption)
{
case 'plain':
return $plaintext;
case 'sha':
$encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext));
return ($show_encrypt) ? '{SHA}' . $encrypted : $encrypted;
case 'crypt':
case 'crypt-des':
case 'crypt-md5':
case 'crypt-blowfish':
return ($show_encrypt ? '{crypt}' : '') . crypt($plaintext, $salt);
case 'md5-base64':
$encrypted = base64_encode(mhash(MHASH_MD5, $plaintext));
return ($show_encrypt) ? '{MD5}' . $encrypted : $encrypted;
case 'ssha':
$encrypted = base64_encode(mhash(MHASH_SHA1, $plaintext . $salt) . $salt);
return ($show_encrypt) ? '{SSHA}' . $encrypted : $encrypted;
case 'smd5':
$encrypted = base64_encode(mhash(MHASH_MD5, $plaintext . $salt) . $salt);
return ($show_encrypt) ? '{SMD5}' . $encrypted : $encrypted;
case 'aprmd5':
$length = strlen($plaintext);
$context = $plaintext . '$apr1$' . $salt;
$binary = self::_bin(md5($plaintext . $salt . $plaintext));
for ($i = $length; $i > 0; $i -= 16)
{
$context .= substr($binary, 0, ($i > 16 ? 16 : $i));
}
for ($i = $length; $i > 0; $i >>= 1)
{
$context .= ($i & 1) ? chr(0) : $plaintext[0];
}
$binary = self::_bin(md5($context));
for ($i = 0; $i < 1000; $i++)
{
$new = ($i & 1) ? $plaintext : substr($binary, 0, 16);
if ($i % 3)
{
$new .= $salt;
}
if ($i % 7)
{
$new .= $plaintext;
}
$new .= ($i & 1) ? substr($binary, 0, 16) : $plaintext;
$binary = self::_bin(md5($new));
}
$p = array();
for ($i = 0; $i < 5; $i++)
{
$k = $i + 6;
$j = $i + 12;
if ($j == 16)
{
$j = 5;
}
$p[] = self::_toAPRMD5((ord($binary[$i]) << 16) | (ord($binary[$k]) << 8) | (ord($binary[$j])), 5);
}
return '$apr1$' . $salt . '$' . implode('', $p) . self::_toAPRMD5(ord($binary[11]), 3);
case 'md5-hex':
$encrypted = ($salt) ? md5($plaintext . $salt) : md5($plaintext);
return ($show_encrypt) ? '{MD5}' . $encrypted : $encrypted;
case 'sha256':
$encrypted = ($salt) ? hash('sha256', $plaintext . $salt) . ':' . $salt : hash('sha256', $plaintext);
return ($show_encrypt) ? '{SHA256}' . $encrypted : '{SHA256}' . $encrypted;
// 'bcrypt' is the default case starting in CMS 3.2.
case 'bcrypt':
default:
$useStrongEncryption = JCrypt::hasStrongPasswordSupport();
if ($useStrongEncryption === true)
{
$encrypted = password_hash($plaintext, PASSWORD_BCRYPT);
if (!$encrypted)
{
// Something went wrong fall back to sha256.
return static::getCryptedPassword($plaintext, '', 'sha256', false);
}
return ($show_encrypt) ? '{BCRYPT}' . $encrypted : $encrypted;
}
else
{
// BCrypt isn't available but we want strong passwords, fall back to sha256.
return static::getCryptedPassword($plaintext, '', 'sha256', false);
}
}
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JUserHelper::getProfile (   $userId = 0)
static

Gets the user profile information

Paramètres:
integer$userIdThe id of the user.
Renvoie:
object
Depuis:
11.1

Définition à la ligne 209 du fichier helper.php.

Références JEventDispatcher\getInstance(), et JFactory\getUser().

{
if ($userId == 0)
{
$user = JFactory::getUser();
$userId = $user->id;
}
// Get the dispatcher and load the user's plugins.
JPluginHelper::importPlugin('user');
$data = new JObject;
$data->id = $userId;
// Trigger the data preparation event.
$dispatcher->trigger('onContentPrepareData', array('com_users.profile', &$data));
return $data;
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::getRememberCookieData ( )
static

Method to get the remember me cookie data

Renvoie:
mixed An array of information from an authentication cookie or false if there is no cookie
Depuis:
3.2

Définition à la ligne 736 du fichier helper.php.

Références JFactory\getApplication().

{
// Create the cookie name
// Fetch the cookie value
$cookieValue = $app->input->cookie->get($cookieName);
if (!empty($cookieValue))
{
return explode('.', $cookieValue);
}
else
{
return false;
}
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::getSalt (   $encryption = 'md5-hex',
  $seed = '',
  $plaintext = '' 
)
static

Returns a salt for the appropriate kind of password encryption. Optionally takes a seed and a plaintext password, to extract the seed of an existing password, or for encryption types that use the plaintext in the generation of the salt.

Paramètres:
string$encryptionThe kind of password encryption to use. Defaults to md5-hex.
string$seedThe seed to get the salt from (probably a previously generated password). Defaults to generating a new seed.
string$plaintextThe plaintext password that we're generating a salt for. Defaults to none.
Renvoie:
string The generated or extracted salt.
Depuis:
11.1
Note:
Default $encryption will be changed to 'bcrypt' in CMS 3.2 and will at the type used by the PHP PASSWORD_DEFAULT constant until 5.5 is the minimum version required. At that point the default will be PASSWORD_DEFAULT.

Définition à la ligne 489 du fichier helper.php.

{
// Encrypt the password.
switch ($encryption)
{
case 'crypt':
case 'crypt-des':
if ($seed)
{
return substr(preg_replace('|^{crypt}|i', '', $seed), 0, 2);
}
else
{
return substr(md5(mt_rand()), 0, 2);
}
break;
case 'sha256':
if ($seed)
{
return preg_replace('|^{sha256}|i', '', $seed);
}
else
{
}
break;
case 'crypt-md5':
if ($seed)
{
return substr(preg_replace('|^{crypt}|i', '', $seed), 0, 12);
}
else
{
return '$1$' . substr(md5(mt_rand()), 0, 8) . '$';
}
break;
case 'crypt-blowfish':
if ($seed)
{
return substr(preg_replace('|^{crypt}|i', '', $seed), 0, 16);
}
else
{
return '$2$' . substr(md5(mt_rand()), 0, 12) . '$';
}
break;
case 'ssha':
if ($seed)
{
return substr(preg_replace('|^{SSHA}|', '', $seed), -20);
}
else
{
return mhash_keygen_s2k(MHASH_SHA1, $plaintext, substr(pack('h*', md5(mt_rand())), 0, 8), 4);
}
break;
case 'smd5':
if ($seed)
{
return substr(preg_replace('|^{SMD5}|', '', $seed), -16);
}
else
{
return mhash_keygen_s2k(MHASH_MD5, $plaintext, substr(pack('h*', md5(mt_rand())), 0, 8), 4);
}
break;
case 'aprmd5': /* 64 characters that are valid for APRMD5 passwords. */
$APRMD5 = './0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
if ($seed)
{
return substr(preg_replace('/^\$apr1\$(.{8}).*/', '\\1', $seed), 0, 8);
}
else
{
$salt = '';
for ($i = 0; $i < 8; $i++)
{
$salt .= $APRMD5{rand(0, 63)};
}
return $salt;
}
break;
// BCrypt is aliased because a BCrypt has may be requested when it is not present, and so it falls back to
// the default behavior of generating a salt.
case 'bcrypt';
default:
$salt = '';
if ($seed)
{
$salt = $seed;
}
return $salt;
break;
}
}
static JUserHelper::getShortHashedUserAgent ( )
static

Method to get a hashed user agent string that does not include browser version. Used when frequent version changes cause problems.

Renvoie:
string A hashed user agent string with version replaced by 'abcd'
Depuis:
3.2

Définition à la ligne 763 du fichier helper.php.

Références JUri\base(), et JFactory\getApplication().

{
$ua = JFactory::getApplication()->client;
$uaString = $ua->userAgent;
$browserVersion = $ua->browserVersion;
$uaShort = str_replace($browserVersion, 'abcd', $uaString);
return md5(JUri::base() . $uaShort);
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::getUserGroups (   $userId)
static

Method to get a list of groups a user is in.

Paramètres:
integer$userIdThe id of the user.
Renvoie:
array List of groups
Depuis:
11.1

Définition à la ligne 95 du fichier helper.php.

Références JUser\getInstance().

{
// Get the user object.
$user = JUser::getInstance((int) $userId);
return isset($user->groups) ? $user->groups : array();
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::getUserId (   $username)
static

Returns userid if a user exists

Paramètres:
string$usernameThe username to search on.
Renvoie:
integer The user id or 0 if not found.
Depuis:
11.1

Définition à la ligne 288 du fichier helper.php.

Références JFactory\getDbo().

Référencé par JUser\getInstance().

{
// Initialise some variables
$query = $db->getQuery(true)
->select($db->quoteName('id'))
->from($db->quoteName('#__users'))
->where($db->quoteName('username') . ' = ' . $db->quote($username));
$db->setQuery($query, 0, 1);
return $db->loadResult();
}

+ Voici le graphe d'appel pour cette fonction :

+ Voici le graphe des appelants de cette fonction :

static JUserHelper::invalidateCookie (   $userId,
  $cookieName 
)
static

Method to remove a cookie record from the database and the browser

Paramètres:
string$userIdUser ID for this user
string$cookieNameSeries id (cookie name decoded)
Renvoie:
boolean True on success
Depuis:
3.2
Voir également:
JInput::setCookie for more details

Définition à la ligne 690 du fichier helper.php.

Références JFactory\getApplication(), et JFactory\getDbo().

{
$query = $db->getQuery(true);
// Invalidate cookie in the database
$query
->update($db->quoteName('#__user_keys'))
->set($db->quoteName('invalid') . ' = 1')
->where($db->quotename('user_id') . ' = ' . $db->quote($userId));
$db->setQuery($query)->execute();
// Destroy the cookie in the browser.
$app->input->cookie->set($cookieName, false, time() - 42000, $app->get('cookie_path'), $app->get('cookie_domain'), false, true);
return true;
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::removeUserFromGroup (   $userId,
  $groupId 
)
static

Method to remove a user from a group.

Paramètres:
integer$userIdThe id of the user.
integer$groupIdThe id of the group.
Renvoie:
boolean True on success
Depuis:
11.1

Définition à la ligne 113 du fichier helper.php.

Références JUser\getInstance(), et JFactory\getUser().

{
// Get the user object.
$user = JUser::getInstance((int) $userId);
// Remove the user from the group if necessary.
$key = array_search($groupId, $user->groups);
if ($key !== false)
{
// Remove the user from the group.
unset($user->groups[$key]);
// Store the user object.
$user->save();
}
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
return true;
}

+ Voici le graphe d'appel pour cette fonction :

static JUserHelper::setUserGroups (   $userId,
  $groups 
)
static

Method to set the groups for a user.

Paramètres:
integer$userIdThe id of the user.
array$groupsAn array of group ids to put the user in.
Renvoie:
boolean True on success
Depuis:
11.1

Définition à la ligne 155 du fichier helper.php.

Références JFactory\getDbo(), JUser\getInstance(), JFactory\getUser(), et JArrayHelper\toInteger().

{
// Get the user object.
$user = JUser::getInstance((int) $userId);
// Set the group ids.
$user->groups = $groups;
// Get the titles for the user groups.
$query = $db->getQuery(true)
->select($db->quoteName('id') . ', ' . $db->quoteName('title'))
->from($db->quoteName('#__usergroups'))
->where($db->quoteName('id') . ' = ' . implode(' OR ' . $db->quoteName('id') . ' = ', $user->groups));
$db->setQuery($query);
$results = $db->loadObjectList();
// Set the titles for the user groups.
for ($i = 0, $n = count($results); $i < $n; $i++)
{
$user->groups[$results[$i]->id] = $results[$i]->id;
}
// Store the user object.
$user->save();
if (session_id())
{
// Set the group data for any preloaded user objects.
$temp = JFactory::getUser((int) $userId);
$temp->groups = $user->groups;
// Set the group data for the user object in the session.
$temp = JFactory::getUser();
if ($temp->id == $userId)
{
$temp->groups = $user->groups;
}
}
return true;
}

+ Voici le graphe d'appel pour cette fonction :


La documentation de cette classe a été générée à partir du fichier suivant :