Skip to content

Instantly share code, notes, and snippets.

@TiuTalk
Created December 8, 2011 17:38
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 TiuTalk/1447751 to your computer and use it in GitHub Desktop.
Save TiuTalk/1447751 to your computer and use it in GitHub Desktop.
<?php
/**
* Gera um salt aleatório
*
* @param int $tamanho Tamanho do salt
*
* @return string
*/
function geraSaltAleatorio($tamanho = 22) {
return substr(sha1(mt_rand()), 0, $tamanho);
}
$salt = geraSaltAleatorio();
// Senha do usuário, pode ter vindo do $_POST, $_GET ou outro lugar
$senha = 'olá mundo';
// Cria um hash
$hash = md5($senha . $salt);
// Encripta esse hash 1000 vezes
for ($i = 0; $i < 1000; $i++) {
$hash = md5($hash);
}
// Salvamos $hash e $salt no banco de dados
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment