liveBook · Manning

Password authentication

As explained in Grokking Web Application Security

A password is a secret string of characters used to authenticate a user or authorize access to a system.

Passwords are credentials used with usernames to authenticate users. They are valuable targets: a database breach can expose accounts on the application and enable attackers to try reused credentials elsewhere. Never store a password in plain text; store only a value derived with a strong password-hashing algorithm, plus salt and pepper. section 3.8 section 3.11

A password defense should address both theft and guessing:

  • Hash passwords before storage so a leaked database contains hashes rather than directly usable passwords. section 3.8
  • Use a strong algorithm such as bcrypt; older algorithms such as MD5 are weak. section 3.8
  • Treat username-and-password-only login as risky because attackers can rapidly test stolen username and password lists with brute-force tools. section 8.1
  • After a suspected credential breach, clearly tell users what may have been exposed and require password rotation when credentials might have been stolen. section 15.5

Checking a password without storing it

When a user logs in, hash the newly entered password using the stored salt, then compare that result with the stored hash. A match verifies the password without retaining its plain-text form. section 3.8

require 'bcrypt'
include BCrypt::Engine

password = "my_topsecretpassword"
salt     = generate_salt
hash     = hash_secret(password, salt)              #1

password_to_check = "topsecretpassword"

if hash_secret(password, salt) == hashed_password   #2
  puts "Password is correct!"
else
  puts "Password is incorrect."
end

The Ruby bcrypt listing illustrates generating a salt, hashing a password, and checking a later entry by hashing it again for comparison. section 3.8

How Grokking Web Application Security covers it

How deep it goes
Explains hash-based storage and verification, then identifies brute-force and breach-response risks without detailing multifactor authentication.
Examples
Illustrates bcrypt salt generation and hash comparison, plus attackers testing stolen username-and-password wordlists.
What it assumes
Introduces credentials and password hashing without assuming specialist security knowledge.
What you can do after
Apply it via bcrypt-style hashing to store and verify passwords without retaining plain text.
How it connects
Connects passwords with usernames, hashing, salt, pepper, bcrypt, brute-force attacks, and multifactor authentication.

Also explained in

Compare how 9 books explain password authentication →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Grokking Web Application Security. The section links point to the parts of the book it draws on.