Senhas e Passwords

<< Click to Display Table of Contents >>

Navigation:  Segurança e Otimização >

Senhas e Passwords

Previous pageReturn to chapter overviewNext page

// criptografa password
$pass = password_hash(12345PASSWORD_DEFAULT);
 
// testar o password
if (password_verify(12345$pass)) {
    echo "<p>Senha OK</p>";
else {
    echo "<p>Senha INCORRETA</p>";
}
 
// gravar no banco de dados
 
echo "<code>";
echo password_hash("A"PASSWORD_DEFAULT)."<br>";
echo password_hash(12345PASSWORD_DEFAULT)."<br>";
echo password_hash("Um texto bem longo como a senha"PASSWORD_DEFAULT)."<br>";
echo password_hash("!@#$%¨&&*()"PASSWORD_DEFAULT)."<br>";
echo "</code>";

 
Saida

 

Senha OK

$2y$10$CJuNTqdAXw5P3jsldKJzFOHMBTRjqYcX8oeZh5NfaZaRKfBW94yFC

$2y$10$YWMQ.Em6RMrgQ6Szh6w98emjQ8IqwGl.nPvrYBnqHclaiy/wnZZd6

$2y$10$erC/oQXHhhh2ZQzSsRr19eJETWlI/6xBqlFoiFJEJdyTQIAL58c9q

$2y$10$CkDZOZcdVPQmrSn9I9oeweQwtvlPxLW99mTsvGE2bk.JS3Cv4AXRq