Ecco l'esempio della PHP manual page for crypt():(PHP) Come implementare correttamente crypt()
<?php
$password = crypt('mypassword'); // let the salt be automatically generated
/* You should pass the entire results of crypt() as the salt for comparing a
password, to avoid problems when different hashing algorithms are used. (As
it says above, standard DES-based password hashing uses a 2-character salt,
but MD5-based hashing uses 12.) */
if (crypt($user_input, $password) == $password) {
echo "Password verified!";
}
?>
Perché fa questo lavoro? Lo prendo 'mypassword'
è la password che voglio l'amministratore effettivo da usare. Quindi prima criptico e impostalo uguale a $password
. Ovviamente, ho bisogno di memorizzarlo nel DB. Ma nelle righe successive è usato sia come sale che a cosa sto confrontando, e non capisco come crypt($user_input, $password)
possa essere uguale a $password
, se in quest'ultimo caso ho idealmente la password giusta come $user_input
ma salata con $password
rispetto a $password
. Avrebbe più senso per me se l'ultima riga fosse
if (crypt($user_input) == $password) {
echo "Password verified!";
}
Cosa non capisco?
si dovrebbero usare tecniche più avanzate come md5, sha1 ecc. – dusoft
hah. hah. hah. hahah. se solo tu fossi in questo epico viaggio con me, amico mio. http://stackoverflow.com/questions/2235158/php-sha1-vs-md5-vs-sha256-which-to-use-for-a-php-login – sepiroth