Skip to content

Instantly share code, notes, and snippets.

dzuelke / bcrypt.php
Last active Jul 9, 2020
How to use bcrypt in PHP to safely store passwords (PHP 5.3+ only)
View bcrypt.php
// secure hashing of passwords using bcrypt, needs PHP 5.3+
// see
// salt for bcrypt needs to be 22 base64 characters (but just [./0-9A-Za-z]), see
$salt = substr(strtr(base64_encode(openssl_random_pseudo_bytes(22)), '+', '.'), 0, 22);
// 2y is the bcrypt algorithm selector, see
// 12 is the workload factor (around 300ms on my Core i7 machine), see