Skip to content

Chapter 30 of 38

Password Hashing

Hash, verify, rehash, rate-limit, and securely manage authentication secrets.

36 minutes 10 quick checksBy Subha Prasad
Lesson 30 of 38Course navigation

Lesson content

Read, practise, then check your understanding

Passwords must use adaptive password hashing, never fast hashes or encryption intended for later decryption.

Practical example

<?php
$hash = password_hash($password, PASSWORD_DEFAULT);
if (!password_verify($candidate, $hash)) { throw new AuthenticationException(); }
if (password_needs_rehash($hash, PASSWORD_DEFAULT)) { $hash = password_hash($candidate, PASSWORD_DEFAULT); }

Store the full encoded hash, let PHP manage salts, and rehash after successful login when policy changes. Add rate limits, MFA where appropriate, secure reset tokens, breached-password checks, and generic authentication errors. Keep any pepper outside the database.

Knowledge check

Answer every question correctly to complete this chapter.

Which statement best describes password_hash?
Which PHP term matches this description: Secure password hashing with an adaptive supported algorithm.
Which statement best describes password_verify?
Which PHP term matches this description: Constant-time-compatible verification against a stored hash.
Which statement best describes password_needs_rehash?
Which PHP term matches this description: Detection that a stored hash should be upgraded.
Which statement best describes pepper?
Which PHP term matches this description: An optional server-held secret separate from the database.
Which statement best describes rate limiting?
Which PHP term matches this description: Restricting repeated authentication attempts.

0 of 10 checks passed

Your progress is saved on this device.