CY4: Identity and access: who gets in, and to what

Lesson 2 of 5 · reading 15–25 minutes; practice and project time is on the module page

Defending the login page

🎯You'll be able to

Stop a login page revealing which accounts exist, and slow down guessing without locking real users out for long.

🏠The everyday picture

A building's guard doesn't say "Mr Rao works on floor 4, but that's the wrong badge". They say "I can't let you in", whatever was wrong.

📘What it really is

📝A worked example

Input: the kit's starter login, which says "No such user" or "Wrong password".

Steps:

  1. Replace both with one message: "Wrong user ID or password."
  2. Count failures for the user in the last 15 minutes before checking the password. At 5 or more, refuse with "Too many attempts. Try again in 15 minutes." even if the password is right.
  3. Record every attempt in login_attempts.

Expected output: unknown users and wrong passwords get the same message; the sixth try within 15 minutes is refused; after 15 minutes the right password works again.

🌍Where it's used

📝Case scenario

A university's login page said "This student ID doesn't exist" for unknown IDs. Someone collected a full list of valid IDs and then tried common passwords on all of them. Changing to one message, plus short lockouts, made the same attempt far slower and visible.

🖱️Try it

Visit the "forgot password" page of a service you use and enter an address that has no account. Success: you can say whether the reply reveals that the account doesn't exist.

⚠️Common mistakes

🛠️For your project

Test 6 checks the single message, the lock after five failures, and that the lock ends after 15 minutes.

✅Quick check

Why should "no such user" and "wrong password" give the same message?

Show the answer

So nobody can find out which accounts exist.

What's the risk of a permanent lockout?

Show the answer

Anyone can lock out a real user on purpose.

← PreviousStoring passwords safely
ProLearners Assist