mirror of
https://github.com/gamaio/UnPS-API.git
synced 2024-11-12 03:57:26 +00:00
Include HashPass
This commit is contained in:
parent
2ce9fc4bf5
commit
8bd2694f9a
40
hashpass.php
Normal file
40
hashpass.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
/* HashPass() function takes $plaintext, $salt and $i (number of iterations) as inputs and outputs $hashpass - $salt and $i are optional
|
||||
* Copyright David Todd (C) 2012
|
||||
* http://www.unps-gama.info
|
||||
* This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
|
||||
* To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
|
||||
* If no $salt provided, generate large int and output $hashpass and $salt
|
||||
* If no $i (number of iterations) provided, go through once and return - not as secure as using iterations, but chances are low it will get cracked easily
|
||||
* If no $plaintext provided, die with error message saved to error variable
|
||||
*/
|
||||
|
||||
function hashpass($plaintext, $salt, $i){
|
||||
if($plaintext == null) die("No password given"); // Die with error
|
||||
$plaintext = hash("sha1", $plaintext); // First step - get plaintext sha1
|
||||
if($salt == null || $salt == ''){
|
||||
$salt = mt_rand(10000, 20000); // Generate random number between 1000 and 20000
|
||||
$salt = hash("sha1", $salt); // Get sha1 hash of random number
|
||||
$salt = $salt.mt_rand(5000, 80000); // Append new random number between 5000 and 80000 to md5 salt
|
||||
$salt = hash("sha256", $salt); // Take a sha256 hash of new salt and done with salt generation
|
||||
}
|
||||
if($i == null || $i == ''){
|
||||
$plaintext = hash("sha256", $plaintext.$salt); // Take first sha256 hash of $plaintext+$salt (64 bits)
|
||||
$plaintext = hash("sha1", $salt.$plaintext.$salt); // Take sha1 of salt+plaintext+salt (32 bits)
|
||||
$plaintext = hash("sha512", $salt.$plaintext.$salt.$salt.$plaintext.$salt); // Take sha512 of this (128bits)
|
||||
$hashpass = hash("sha256", $plaintext); // final hash is sha256 of the sha512 above (back down to 64bits)
|
||||
return $hashpass."/".$salt; // Give calling script the hashed password and salt, seperate strings with "/" to be exploded into array later
|
||||
}else{
|
||||
$il = '';
|
||||
while($il < $i && $il <= 50){
|
||||
$plaintext = hash("sha256", $plaintext.$salt); // Take first sha256 hash of $plaintext+$salt (64 bits)
|
||||
$plaintext = hash("sha1", $salt.$plaintext.$salt); // Take sha1 of salt+plaintext+salt (32 bits)
|
||||
$plaintext = hash("sha512", $salt.$plaintext.$salt.$salt.$plaintext.$salt); // Take sha512 of this (128bits)
|
||||
$il++;
|
||||
//echo "Iteration: $il Password: $plaintext\r\n";
|
||||
}
|
||||
$hashpass = hash("sha256", $plaintext); // final hash is sha256 of the sha512 above (back down to 64bits)
|
||||
return $hashpass."/".$salt; // Give calling script the hashed password and salt, seperate strings with "/" to be exploded into array later
|
||||
}
|
||||
}
|
||||
?>
|
Loading…
Reference in New Issue
Block a user