Hash and verify a password in PHP

Php

password_hash picks the algorithm and the salt. Never store anything a hash function can reverse.

$hash = password_hash($plain, PASSWORD_DEFAULT);

if (password_verify($submitted, $hash)) {
    if (password_needs_rehash($hash, PASSWORD_DEFAULT)) {
        $hash = password_hash($submitted, PASSWORD_DEFAULT);
    }
}

More in PHP

Random picks