Blog · 1 October 2026

Eight holes in a typical PHP login system

A login system has an awkward property: it looks finished long before it is safe. The form accepts a password, the dashboard appears, and nothing on screen tells you what an attacker can do.

These eight flaws all appeared together in one early PHP login prototype, the kind you get from a tutorial or an AI assistant. Each has a one-minute test you can run against your own app.

1. The database can be downloaded

The flaw. The SQLite file sits in a folder the web server serves, such as backend/database.sqlite.

The test. Type the file's address into your browser. If a download starts, anyone can take every email address and password hash you hold.

The fix. Keep only public files in the web root. Code, data and logs go in folders beside it, where no address reaches them.

2. The dashboard is protected by JavaScript

The flaw. The page is static HTML. A script on it asks the server "is this user signed in?" and redirects if not.

The test. Turn JavaScript off, or choose View Source. If you can read the page, so can everyone. The check runs after the page has already been delivered.

The fix. Check on the server before any HTML is produced. A guest should receive a redirect and none of the page.

3. No protection against forged requests

The flaw. A form on another website can submit to your app, and the visitor's browser attaches their session cookie. Your app can't tell that from a real click on Save.

The test. Look at your forms' HTML. If there's no hidden random token, and the handler doesn't check one, you're exposed.

The fix. Put a secret per-session token in every form and refuse any POST without the right one. It's ten lines of code.

4. Unlimited password guesses

The flaw. Nothing counts failed sign-ins.

The test. Enter a wrong password ten times quickly. If the eleventh attempt is treated like the first, a script can try thousands of passwords a minute.

The fix. Count failures per email and IP address in the database, and stop after a handful for fifteen minutes. Keep the count in the database, not the session: an attacker simply throws the session cookie away.

5. Security settings that exist only in the README

The flaw. The documentation says cookies are Secure and SameSite, but the code never sets them. This one is easy to miss, because you read the claim and move on.

The test. Open your browser's developer tools, find the session cookie, and read its flags. Believe the cookie, not the README.

The fix. Set HttpOnly, SameSite and (over HTTPS) Secure explicitly before the session starts.

6. Hashing that crashes on cheap hosting

The flaw. The code asks for Argon2id by name. Some shared hosts build PHP without it, and the request fails with a fatal error. On those hosts, nobody can register.

The test. Run php -r "var_dump(defined('PASSWORD_ARGON2ID'));" on your host.

The fix. Use Argon2id where it exists and fall back to bcrypt where it doesn't. Then call password_needs_rehash() at sign-in, so hashes upgrade themselves if you move to a better host.

7. Two accounts for one email address

The flaw. Email comparison is case-sensitive. Len@example.com and len@example.com become different accounts, which confuses users and breaks password resets.

The test. Register twice with the same address in different capitals.

The fix. Lower-case every email before storing or looking it up, and make the database's unique index case-insensitive as a backstop.

8. The parts nobody demos

The flaw. No password reset, no session timeout, no security headers, no error log. None of these appears in a demo of "signing in", so none gets built.

The test. Ask what happens when a user forgets their password, walks away from a shared computer, or hits an error at 2 a.m. If the answers are "they can't", "nothing" and "I'd never know", that's the gap.

The fix. Reset links that are random, stored hashed, single-use and short-lived. Sessions that expire on the server. A Content-Security-Policy. Errors written to a log and never shown to visitors.

Why they travel together

None of these breaks the happy path. Sign-up works, sign-in works, the dashboard loads. Each flaw only shows itself when somebody goes looking, and the first person to look is rarely you. On your own project that's a lesson. On an app you built for a client, it's their customers' accounts and your name.

That's the case for starting from code where someone has already looked. VanillaSaaS Core closes all eight, and its security model lists what it does and doesn't defend against.