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$nBVNsPdvrypU5w8JQX1rTOnO8KTAP.w2.VDwDi89ACRfz.vi0E3V2

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$4GPzRYRPX/P99RZtvcyBYO8O9Z9iNW5shy.9tE1KmJvBEcam1I8hy


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$mK7DmPaFKpcePcNJrt.Sbee9DUZks4yoSu94rxRLOEjYhf/bjHhJe

Password is valid!

time : 0.573s