Quick and easy password storage with PHP

Store passwords (e.g., in a database) as salted hashes, with built-in PHP functionality (using my super 3l33t system operator password):

$hash_to_store_in_db = password_hash('god',  PASSWORD_DEFAULT);

To verify a user-submitted password against the salted hash:

if( password_verify($password, $hash) ) { ... }

To generate such a hash from the command line (e.g., to manually update a database table if necessary):

$ echo "<?php echo password_hash('god',  PASSWORD_DEFAULT); ?>" | php

Easy.


Comments