Source for file simple.php
Documentation is available at simple.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Joomla Platform Password Crypter
* @package Joomla.Platform
* @var integer The cost parameter for hashing algorithms.
* @var string The default hash type
* Creates a password hash
* @param string $password The password to hash.
* @param string $type The hash type.
* @return mixed The hashed password or false if the password is too long.
* @throws InvalidArgumentException
public function create($password, $type =
null)
// We set a maximum length to prevent abuse since it is unfiltered and not all controllers check.
// 55 is the maximum for bcrypt currently the strongest available method:
return crypt($password, $salt);
return crypt($password, $salt);
return md5($password .
$salt) .
':' .
$salt;
throw
new InvalidArgumentException(sprintf('Hash type %s is not supported', $type));
* Sets the cost parameter for the generated hash for algorithms that use a cost factor.
* @param integer $cost The new cost value.
* Generates a salt of specified length. The salt consists of characters in the set [./0-9A-Za-z].
* @param integer $length The number of characters to return.
* @return string The string of random characters.
protected function getSalt($length)
$bytes =
ceil($length *
6 /
8);
return substr($randomData, 0, $length);
* Verifies a password hash
* @param string $password The password to verify.
* @param string $hash The password hash to check.
* @return boolean True if the password is valid, false otherwise.
public function verify($password, $hash)
// Check if the hash is a blowfish hash.
if (substr($hash, 0, 4) ==
'$2a$' ||
substr($hash, 0, 4) ==
'$2y$')
$hash =
$type .
substr($hash, 4);
return (crypt($password, $hash) ===
$hash);
// Check if the hash is an MD5 hash.
if (substr($hash, 0, 3) ==
'$1$')
return (crypt($password, $hash) ===
$hash);
// Check if the hash is a Joomla hash.
if (preg_match('#[a-z0-9]{32}:[A-Za-z0-9]{32}#', $hash) ===
1)
* @param string $type The value to set as default.
* @return string $type The default type
Documentation generated on Tue, 19 Nov 2013 15:12:59 +0100 by phpDocumentor 1.4.3