Source code for file /joomla/user/helper.php
Documentation is available at helper.php
* @version $Id: authenticate.php 6257 2007-01-11 22:03:46Z friesengeist $
* @package Joomla.Framework
* @copyright Copyright (C) 2005 - 2007 Open Source Matters. All rights reserved.
* @license GNU/GPL, see LICENSE.php
* Joomla! is free software. This version may have been modified pursuant
* to the GNU General Public License, and as distributed it includes or
* is derivative of works licensed under the GNU General Public License or
* other free or open source software licenses.
* See COPYRIGHT.php for copyright notices and details.
* Authorization helper class, provides static methods to perform various tasks relevant
* to the Joomla user and authorization classes
* This class has influences and some method logic from the Horde Auth package
* @package Joomla.Framework
* Method to activate a user
* @param string $activation Activation string
* @return boolean True on success
//Initialize some variables
// Lets get the id of the user we want to activate
.
' WHERE activation = "'.
$activation.
'"'
$id =
intval( $db->loadResult() );
// Is it a valid user to activate?
$user->set('block', '0');
$user->set('activation', '');
// Time to take care of business.... store the user.
* Returns userid if a user exists
* @param string The username to search on
* @return int The user id or 0 if not found
// Initialize some variables
$query =
'SELECT id FROM #__users WHERE username = ' .
$db->Quote( $username );
$db->setQuery($query, 0, 1);
return $db->loadResult();
* Formats a password using the current encryption.
* @param string $plaintext The plaintext password to encrypt.
* @param string $salt The salt to use to encrypt the password. []
* If not present, a new salt will be
* @param string $encryption The kind of pasword encryption to use.
* @param boolean $show_encrypt Some password systems prepend the kind of
* encryption to the crypted password ({SHA},
* etc). Defaults to false.
* @return string The encrypted password.
function getCryptedPassword($plaintext, $salt =
'', $encryption =
'md5-hex', $show_encrypt =
false)
return ($show_encrypt) ?
'{SHA}'.
$encrypted :
$encrypted;
return ($show_encrypt ?
'{crypt}' :
'').
crypt($plaintext, $salt);
return ($show_encrypt) ?
'{MD5}'.
$encrypted :
$encrypted;
$encrypted =
base64_encode(mhash(MHASH_SHA1, $plaintext.
$salt).
$salt);
return ($show_encrypt) ?
'{SSHA}'.
$encrypted :
$encrypted;
$encrypted =
base64_encode(mhash(MHASH_MD5, $plaintext.
$salt).
$salt);
return ($show_encrypt) ?
'{SMD5}'.
$encrypted :
$encrypted;
$context =
$plaintext.
'$apr1$'.
$salt;
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];
for ($i =
0; $i <
1000; $i ++
) {
$new =
($i & 1) ?
$plaintext :
substr($binary, 0, 16);
$new .=
($i & 1) ?
substr($binary, 0, 16) :
$plaintext;
for ($i =
0; $i <
5; $i ++
) {
$p[] =
JUserHelper::_toAPRMD5((ord($binary[$i]) <<
16) |
(ord($binary[$k]) <<
8) |
(ord($binary[$j])), 5);
return ($show_encrypt) ?
'{MD5}'.
md5($plaintext) :
md5($plaintext);
* 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 string $encryption The kind of pasword encryption to use.
* @param string $seed The seed to get the salt from (probably a
* previously generated password). Defaults to
* @param string $plaintext The plaintext password that we're generating
* a salt for. Defaults to none.
* @return string The generated or extracted salt.
function getSalt($encryption =
'md5-hex', $seed =
'', $plaintext =
'')
/* 64 characters that are valid for APRMD5 passwords. */
$APRMD5 =
'./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
for ($i =
0; $i <
8; $i ++
) {
* Generate a random password
* @param int $length Length of the password to generate
* @return string Random Password
$salt =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
for ($i =
0; $i <
$length; $i ++
) {
$makepass .=
$salt[mt_rand(0, $len -
1)];
* Converts to allowed 64 characters for APRMD5 passwords.
* @return string $value converted to the 64 MD5 characters.
function _toAPRMD5($value, $count)
/* 64 characters that are valid for APRMD5 passwords. */
$APRMD5 =
'./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';
$aprmd5 .=
$APRMD5[$value & 0x3f];
* Converts hexadecimal string to binary data.
* @param string $hex Hex data.
* @return string Binary data.
for ($i =
0; $i <
$length; $i +=
2) {