Blogroll

Thursday, January 12, 2012

Create custom hash.

I refer use crypt() instead md5 or sha256, because of crypt proviced many hash method and key to decode is automatic created -> hard to crack.





$password = crypt('mypassword'); // let the salt be automatically generated

echo $password.'
 and count is'.strlen($password).'
';
/* 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.) */
   $user_input = 'mypassword';
if (crypt($user_input,'$6$rounds=5000$usesomesillystringforsalt$') == $password) {
   echo "Password verified!";
}
else
    echo 'Password not verified';

In other way, you can define the key to open

$password = crypt('mypassword','$6$rounds=5000$usesomesillystringforsalt$'); // Hash with sha 256 

echo $password.'
and count is'.strlen($password).'
'; /* 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.) */ $user_input = 'mypassword'; if (crypt($user_input,'$6$rounds=5000$usesomesillystringforsalt$') == $password) { echo "Password verified!"; } else echo 'Password not verified';

Also have some algorith available

if (CRYPT_STD_DES == 1) {
    echo 'Standard DES: ' . crypt('rasmuslerdorf', 'rl') . "\n";
}

if (CRYPT_EXT_DES == 1) {
    echo 'Extended DES: ' . crypt('rasmuslerdorf', '_J9..rasm') . "\n";
}

if (CRYPT_MD5 == 1) {
    echo 'MD5:          ' . crypt('rasmuslerdorf', '$1$rasmusle$') . "\n";
}

if (CRYPT_BLOWFISH == 1) {
    echo 'Blowfish:     ' . crypt('rasmuslerdorf', '$2a$07$usesomesillystringforsalt$') . "\n";
}

if (CRYPT_SHA256 == 1) {
    echo 'SHA-256:      ' . crypt('rasmuslerdorf', '$5$rounds=5000$usesomesillystringforsalt$') . "\n";
}

if (CRYPT_SHA512 == 1) {
    echo 'SHA-512:      ' . crypt('rasmuslerdorf', '$6$rounds=5000$usesomesillystringforsalt$') . "\n";
}
Olá! Se você ainda não assinou, assine nosso RSS feed e receba nossas atualizações por email, ou siga nos no Twitter.
Nome: Email:

0 comments:

Post a Comment