Файл: upload/include/library/phpfox/hash/hash.class.php
Строк: 72
<?php
/**
* [PHPFOX_HEADER]
*/
defined('PHPFOX') or exit('NO DICE!');
/**
* Random Hash Creator
* Creates a random hash for passwords as well as create a random hash for cookies were X will
* always have a different hash value due to a random prefix.
*
* Example to create a hashed password:
* <code>
* Phpfox::getLib('hash')->setHash('password', 'salt');
* </code>
*
* @copyright [PHPFOX_COPYRIGHT]
* @author Raymond Benc
* @package Phpfox
* @version $Id: hash.class.php 1666 2010-07-07 08:17:00Z Raymond_Benc $
*/
final class Phpfox_Hash
{
/**
* Class constructor
*
*/
public function __construct()
{
}
/**
* Creates an MD5 hash with the password itself wrapped in MD5 as
* well as support for a random salt that is also wrapped in MD5
*
* @see md5()
* @param string $sPassword Password to create a hash for
* @param string $sSalt Optional random salt to make the hash unique
* @return string Returns a 32 character MD5 string
*/
public function setHash($sPassword, $sSalt = '')
{
if (!$sSalt)
{
$sSalt = Phpfox::getParam('core.salt');
}
if ($sPlugin = Phpfox_Plugin::get('hash_sethash__end')){eval($sPlugin);}
return md5(md5($sPassword) . md5($sSalt));
}
/**
* Creates a random hash for a password that needs to be set in a public state, usually a session
* or a cookie
*
* @see sha1()
* @see md5()
* @param string $sPassword Password or information we need to create a hash for
* @return string Returns a sha1 string
*/
public function setRandomHash($sPassword)
{
$sSeed = '';
for ($i = 1; $i <= 10; $i++)
{
$sSeed .= substr('0123456789abcdef', rand(0, 15), 1);
}
return sha1($sSeed . md5($sPassword) . $sSeed) . $sSeed;
}
/**
* Verifies if the hash we created earlier with the method setRandomHash() matches.
*
* @see self::setRandomHash()
* @param string $sPassword Password or information we need to check with our stored hash
* @param string $sStoredValue Stored sha1 hash. Usually a cookie or session
* @return bool TRUE on success, FALSE on failure
*/
public function getRandomHash($sPassword, $sStoredValue)
{
if (strlen($sStoredValue) != 50)
{
return false;
}
$sStoredSeed = substr($sStoredValue, 40, 10);
if (sha1($sStoredSeed . md5($sPassword) . $sStoredSeed) . $sStoredSeed == $sStoredValue)
{
return true;
}
else
{
return false;
}
}
}
?>