-
-
Save parzibyte/5637a920789836dcd5bf929baafeafc0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function token($length = 32) { | |
// Create random token | |
$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | |
$max = strlen($string) - 1; | |
$token = ''; | |
for ($i = 0; $i < $length; $i++) { | |
$token .= $string[mt_rand(0, $max)]; | |
} | |
return $token; | |
} | |
function generar_pass($passTextoPlano){ | |
$sal = token(9); | |
$hash = sha1($sal . sha1($sal . sha1($passTextoPlano))); | |
return [ | |
"sal" => $sal, | |
"hash" => $hash, | |
]; | |
} | |
// Demostrar uso | |
$datosPass = generar_pass("hunter2"); | |
$pass = $datosPass["hash"]; // Este va en el campo password | |
$sal = $datosPass["sal"]; // Este va en el campo salt | |
printf("La sal es %s y la pass es %s", $sal, $pass); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment