HomeTopicsA07 Authentication Failures
Lesson 7 / 10

A07: Authentication Failures

Authentication failures occur when attackers can compromise passwords, keys, or session tokens, or exploit implementation flaws to assume other users' identities temporarily or permanently.

Key Vulnerabilities

1

Permitting brute force and credential stuffing attacks

2

Allowing weak or well-known passwords (e.g., 'password123')

3

Using weak credential recovery processes (knowledge-based answers)

4

Storing passwords in plain text or using weak hashing

5

Missing or ineffective multi-factor authentication

6

Exposing session identifiers in URLs

Prevention Strategies

Implement multi-factor authentication (MFA)

Never ship with default credentials

Check passwords against breached password lists (Have I Been Pwned)

Enforce password length, complexity, and rotation policies

Limit and delay failed login attempts

Use server-side, secure session manager with random session IDs

Real-World Example

In 2019, credential stuffing attacks using previously breached passwords affected millions of accounts across streaming services, food delivery, and retail platforms.

Code Comparison

Vulnerable Code
// VULNERABLE: No brute-force protection, weak session
app.post('/login', (req, res) => {
  const user = db.findUser(req.body.email);
  if (user.password === req.body.password) {  // Plain text!
    res.cookie('session', user.id);           // Predictable!
    res.json({ success: true });
  }
});
Secure Code
// SECURE: Rate limiting, bcrypt, secure sessions
app.post('/login', loginLimiter, async (req, res) => {
  const user = db.findUser(req.body.email);
  if (!user) return res.status(401).json({
    error: 'Invalid credentials'  // Generic message
  });
  const valid = await bcrypt.compare(req.body.password, user.hash);
  if (!valid) { recordFailedAttempt(user.id); return; }
  req.session.regenerate();  // New session ID
  req.session.userId = user.id;
});