JUserHelper
Authorisation helper class, provides static methods to perform various tasks relevant to the Joomla user and authorisation classes
This class has influences and some method logic from the Horde Auth package
| package |
Joomla.Platform |
|---|---|
| subpackage |
User |
| since |
11.1 |
Methods
_bin
Converts hexadecimal string to binary data.
_bin(string $hex) : string
| since |
11.1 |
|---|
Arguments
- $hex
stringHex data.
Response
stringBinary data.
_toAPRMD5
Converts to allowed 64 characters for APRMD5 passwords.
_toAPRMD5(string $value, integer $count) : string
| since |
11.1 |
|---|
Arguments
- $value
stringThe value to convert.- $count
integerThe number of characters to convert.
Response
string$value converted to the 64 MD5 characters.
activateUser
Method to activate a user
activateUser(string $activation) : boolean
| since |
11.1 |
|---|
Arguments
- $activation
stringActivation string
Response
booleanTrue on success
addUserToGroup
Method to add a user to a group.
addUserToGroup(integer $userId, integer $groupId) : mixed
| since |
11.1 |
|---|
Arguments
- $userId
integerThe id of the user.- $groupId
integerThe id of the group.
Response
mixedBoolean true on success, Exception on error.
genRandomPassword
Generate a random password
genRandomPassword(integer $length = 8) : string
| since |
11.1 |
|---|
Arguments
- $length
integerLength of the password to generate
Response
stringRandom Password
getCryptedPassword
Formats a password using the current encryption.
getCryptedPassword(string $plaintext, string $salt = '', string $encryption = 'md5-hex', boolean $show_encrypt = false) : string
| since |
11.1 |
|---|---|
| deprecated |
4.0 |
Arguments
- $plaintext
stringThe plaintext password to encrypt.- $salt
stringThe salt to use to encrypt the password. [] If not present, a new salt will be generated.- $encryption
stringThe kind of password encryption to use. Defaults to md5-hex.- $show_encrypt
booleanSome password systems prepend the kind of encryption to the crypted password ({SHA}, etc). Defaults to false.
Response
stringThe encrypted password.
getProfile
Gets the user profile information
getProfile(integer $userId) : object
| since |
11.1 |
|---|
Arguments
- $userId
integerThe id of the user.
Response
object
getSalt
Returns a salt for the appropriate kind of password encryption.
getSalt(string $encryption = 'md5-hex', string $seed = '', string $plaintext = '') : string
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.
| since |
11.1 |
|---|
Arguments
- $encryption
stringThe kind of password encryption to use. Defaults to md5-hex.- $seed
stringThe seed to get the salt from (probably a previously generated password). Defaults to generating a new seed.- $plaintext
stringThe plaintext password that we're generating a salt for. Defaults to none.
Response
stringThe generated or extracted salt.
getUserGroups
Method to get a list of groups a user is in.
getUserGroups(integer $userId) : mixed
| since |
11.1 |
|---|
Arguments
- $userId
integerThe id of the user.
Response
mixedArray on success, JException on error.
getUserId
Returns userid if a user exists
getUserId(string $username) : integer
| since |
11.1 |
|---|
Arguments
- $username
stringThe username to search on.
Response
integerThe user id or 0 if not found.
hashPassword
Hashes a password using the current encryption.
hashPassword(string $password) : string
| since |
3.2.1 |
|---|
Arguments
- $password
stringThe plaintext password to encrypt.
Response
stringThe encrypted password.
removeUserFromGroup
Method to remove a user from a group.
removeUserFromGroup(integer $userId, integer $groupId) : mixed
| since |
11.1 |
|---|
Arguments
- $userId
integerThe id of the user.- $groupId
integerThe id of the group.
Response
mixedBoolean true on success, JException on error.
setUserGroups
Method to set the groups for a user.
setUserGroups(integer $userId, array $groups) : mixed
| since |
11.1 |
|---|
Arguments
- $userId
integerThe id of the user.- $groups
arrayAn array of group ids to put the user in.
Response
mixedBoolean true on success, Exception on error.
verifyPassword
Formats a password using the current encryption. If the user ID is given and the hash does not fit the current hashing algorithm, it automatically updates the hash.
verifyPassword(string $password, string $hash, integer $user_id) : boolean
| since |
3.2.1 |
|---|
Arguments
- $password
stringThe plaintext password to check.- $hash
stringThe hash to verify against.- $user_id
integerID of the user if the password hash should be updated
Response
booleanTrue if the password and hash match, false otherwise