Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created April 1, 2019 01:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/5637a920789836dcd5bf929baafeafc0 to your computer and use it in GitHub Desktop.
Save parzibyte/5637a920789836dcd5bf929baafeafc0 to your computer and use it in GitHub Desktop.
<?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