Intro to Authentication & Membership Features / Chapter 1 — Fundamentals of Authentication (lessons 1–5) / Lesson 1

Storing Passwords with a Salted Hash

Time needed: about 3 min (estimate)

☆ Read later

You can try the opening of this lesson without an account.

What happens when you store passwords in plain text

Store a password as-is in the database, and the moment the database leaks, every single password leaks with it.

Users often reuse the same password across multiple services, so the damage spreads to other services too.

That's why passwords are stored as a one-way hash (a transformation that can't be reversed), and at login you check by "hashing the input the same way and seeing if it matches the stored hash."

The difference in how it's stored

# ❌ stored as plain text password = "correct horse battery staple" ← if the DB leaks, it's read as-is # ✅ store as a salted one-way hash password = make_password("correct horse battery staple") → becomes a string unrelated to the plain text, and can't be reversed

What salt is actually for

Create a free account to keep reading

With an account you can read the rest of this lesson, take the quiz, and read every free lesson in this course. Lessons you answer correctly are recorded as complete.

Report a problem with this lesson

Log in to send a report.

Keyboard shortcuts

Keys available in a lesson
KeyAction
[ or Alt + ←Go to the previous lesson
] or Alt + →Go to the next lesson
?Open this list
EscClose this list

The keys do not work while the cursor is in a code editor or an input field.