note 113526 added to function.hash
| From: | Anonymous | Date: | Fri, 25 Oct 2013 01:10:25 +0000 |
| Subject: | note 113526 added to function.hash | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-197319@lists.php.net to get a copy of this message | ||
I use this code for Secure Password Hashes
<?php
class SecurLoginHashing {
/**
* System Salt
* @var string
*/
protected $salt = '';
/**
* Hashing Iterations >= 1
* @var int
*/
protected $iterations = 2;
/**
* Hashing algorithm used each iteration
* @var string[]
*/
protected $algorithms = array();
/**
* @param string $salt
* @param int $iterations [Default: 2]
* @param string[] $algorithms [Default: array('sha512', 'ripemd320',
'whirlpool')]
*/
public function __construct( $salt, $iterations = 2, $algorithms = array('sha512',
'ripemd320', 'whirlpool')) {
$this->salt = $salt;
$this->iterations = $iterations;
$this->algorithms = $algorithms;
}
/**
* Generating a Safe Hash in Obj. Context
* @param string $toHash
* @param string $user_salt
* @return string
*/
public function hash($toHash, $user_salt){
return self::staticHash($toHash, $user_salt, $this->salt, $this->iterations,
$this->algorithms);
}
/**
* Generating a Safe Hash in static Context
* @param string $toHash
* @param string $user_salt
* @param string $salt
* @param int $iterations [Default: 2]
* @param string[] $algorithms [Default: array('sha512', 'ripemd320',
'whirlpool')]
* @return string
*/
public static function staticHash($toHash, $user_salt, $salt, $iterations = 2, $algorithms =
array('sha512', 'ripemd320', 'whirlpool')) {
$i=0;
do {
// Salting
$toHash = $user_salt.$toHash.$salt;
// Avoid Collision Attacks with different algorithms
$tempHash = '';
foreach($algorithms as $algo) {
$tempHash .= \hash($algo, $toHash);
}
// Reset Hash length
$toHash = \hash($algo, $tempHash);
$i++;
} while ($i<$iterations);
return $toHash;
}
}
?>
----
Server IP: 72.52.91.12
Probable Submitter: 72.52.91.12
----
Manual Page -- http://php.net/manual/en/function.hash.php
Edit -- https://master.php.net/note/edit/113526
Del: integrated -- https://master.php.net/note/delete/113526/integrated
Del: useless -- https://master.php.net/note/delete/113526/useless
Del: bad code -- https://master.php.net/note/delete/113526/bad+code
Del: spam -- https://master.php.net/note/delete/113526/spam
Del: non-english -- https://master.php.net/note/delete/113526/non-english
Del: in docs -- https://master.php.net/note/delete/113526/in+docs
Del: other reasons-- https://master.php.net/note/delete/113526
Reject -- https://master.php.net/note/reject/113526
Search -- https://master.php.net/manage/user-notes.php