← All projects

Security · Personal project

Secure Login System

A desktop login system I built to go deeper into authentication after my password manager: validated sign-up, bcrypt-hashed passwords, TOTP two-factor authentication with QR-code enrolment, and a per-user account dashboard.

  • Python
  • bcrypt
  • PyOTP (TOTP)
  • SQLite
  • CustomTkinter

How it works

Users sign in with a username and password. If the password matches and 2FA is off, they go straight to their dashboard. If 2FA is on, they're asked for the six-digit code from their authenticator app, and nothing is shown until it's correct. From the dashboard they can turn 2FA on (which generates a QR code to scan) or off, and log out.

Security

  • Password hashing: bcrypt with a cost factor of 12; plain-text passwords are never stored.
  • Two-factor authentication: time-based one-time passwords (TOTP, RFC 6238) via PyOTP with 30-second codes, enrolled by scanning an otpauth:// QR code.
  • SQL injection prevention: every query uses parameterised sqlite3 placeholders, never string formatting.
  • Secrets out of code: the app secret is generated with Python's secrets module and loaded from the environment, not hard-coded.
  • Input validation on sign-up: usernames limited to safe characters; passwords at least 8 characters with letters and numbers, confirmed twice; names letters only; age 1–120; email format checked.
  • Audit logging of key events with Python's logging module.

What I'd improve next

Reviewing it now, these are the changes I'd make first:

  • Give every user their own TOTP secret (e.g. pyotp.random_base32() at enrolment), stored encrypted. At the moment one app-wide secret is shared by all accounts.
  • Generate a fresh bcrypt salt for each password rather than reusing one created when the app starts.
  • Lock or slow down accounts after repeated failed logins or 2FA attempts.
  • Show the enrolment QR code in the app instead of saving it to disk.