PHP crypt() functions

Standard DES: stqAdD7zlbByI

Extended DES: _S4..someQXidlBpTUu6

CRYPT_MD5 : $1$somethin$4NZKrUlY6r7K7.rdEOZ0w.

Blowfish: $2a$09$anexamplestringforsaleLouKejcjRlExmf1671qw3Khl49R3dfu

SHA-256: $5$rounds=5000$anexamplestringf$KIrct ↵
qsxo2wrPg5Ag/hs4jTi4PmoNKQUGWFXlVy9vu

SHA-512: $6$rounds=5000$anexamplestringf$Oo0skOAdUFXkQxJpwzO05wgRHG0 ↵
dhuaPBaOU/oNbGpCEKlf/7oVM5wn6AN0w2vwUgA0O24oLzGQpp1XKI6LLQ0

Source ➠ http://www.w3schools.com/php/func_string_crypt.asp
More info ➠ http://php.net/manual/en/faq.passwords.php


PHP password_hash() function

Create hash ➠ http://php.net/manual/en/function.password-hash.php

Verify hash ➠ http://php.net/manual/en/function.password-verify.php

If your PHP version (> 5.3.7 AND < 5.5.0) does not support the password_hash() function (You'll get an internal server error and you won't see output) then use this library :

https://github.com/ircmaxell/password_compat


password_hash("rasmuslerdorf", PASSWORD_DEFAULT)

$hash = password_hash("rasmuslerdorf", PASSWORD_DEFAULT);

echo "<p>password hash() : " . $hash . "</p>";

if (password_verify('rasmuslerdorf', $hash)) {
    echo '<p>Password is valid!</p>';
} else {
    echo '<p>Invalid password.</p>';
}

password hash() : $2y$10$G7Xufgu4JVnd1Y2ecZR.Ie68RCbYbvOtyhyFrjjtTnop6YFj93nNe

Password is valid!


password_hash("rasmuslerdorf", PASSWORD_BCRYPT)

$hash3 = password_hash("rasmuslerdorf", PASSWORD_BCRYPT);

echo "<p>password hash with bcrypt only : " . $hash3 . "</p>";

password hash with bcrypt only :
$2y$10$x4E7OYDBbCGF2KGNtKQXY.C1ffMisibmi7vjwg1VA0QbgXMEt4pFq


password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)

$options = [
    'cost' => 12,
];

$hash2 = password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options);

echo "<p>password hash with bcrypt and cost : " . $hash2 . "</p>\n";

if (password_verify('rasmuslerdorf', $hash)) {
    echo '<p>Password is valid!</p>';
} else {
    echo '<p>Invalid password.</p>';
}

password hash with bcrypt and cost :
$2y$12$ZxcQsLo5O8umZNQh.T70aOPjNM/pxoU8Wm.lY9TO41LXRlaBvy/.C

Password is valid!

time : 0.804s