SUBTASK #86: Sign in and account rules (2.1)

Aperta
#89 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@PavlockBlaine03 ci sta già lavorando.

Dal 2/11/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
python

Direzione di ricerca

Start with the AccessControlService plan in backend/services/access_control/access_control_service.py and the UserStore interface it depends on, then read the test file tests/services/access_control/test_access_control_service.py for the expected cases. The password hashing (BB-5) and #87 are prerequisites, so check whether they exist before writing code. Done means the listed unit tests pass with a fake store and fake clock, and .\dev admin works on an empty database in dev.py.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

backend Medium Priority subtask

What to do

The sign-in check (AccessControlService.authenticate): given a username and password, return the user or the reason they can't sign in. Also the password rule, creating an account and changing a password, plus a command to create the first admin account on a fresh database.

Background

  • Spec SEC-01, SEC-02, CP-02, IN-11; OOD AccessControlService.authenticateUser()
  • UserStore (#17): find_by_username, store(user, changed_by) (audited, and records {"password_changed": true} instead of the hash), create_first_user (refused once any user exists)
  • Password hashing is BB-5 (subtask 1). The password rule and failed sign-in limits are decisions on #PARENT.

Steps

  • backend/services/access_control/access_control_service.py:
    • AccessControlService(users, clock=time.monotonic): users is anything with find_by_username and store (a Protocol, so tests pass a fake); clock lets tests move time forward
    • LoginResult(user: User | None, reason: str | None), frozen
    • authenticate(username, password) -> LoginResult:
      • Unknown username or wrong password: "Username or password is incorrect."
      • Unknown username still runs verify_password against a fixed dummy hash, so the answer takes the same time either way (otherwise the timing reveals which usernames exist)
      • Right password but a disabled account: "This account is disabled. Ask an admin to turn it back on."
      • 5 failures for one username within 15 minutes: "Too many attempts. Try again in N minutes.", without checking the password. A successful sign-in clears the count.
    • check_password_rule(username, password) -> str | None: the reason it's not allowed, or None
    • create_user(username, password, role, created_by) -> result with reasons: username 1 to 100 characters (letters, digits, . _ -), the password rule, and not already taken; then UserStore.store(..., changed_by=created_by)
    • change_password(user, current_password, new_password) -> result with reasons: checks the current password first
  • backend/services/access_control/create_admin.py, run as .\dev admin:
    • Asks for a username, and the password twice with getpass (never as a command-line argument, which would end up in the shell history)
    • Creates an admin with create_first_user; if users already exist, says so and changes nothing
    • Add admin to dev.py and the README
  • Unit tests (a fake user store and a fake clock):
    • Right password signs in
    • Wrong password and unknown username give the same message
    • An unknown username still calls verify_password
    • A disabled account is refused after the right password
    • The 6th attempt is refused even with the right password; after 15 minutes it works; a success resets the count
    • Password rule edges: 11 and 129 characters refused; 12 and 128 allowed; the username as the password refused
    • A taken username is refused
    • A created user is stored with a hash (never the password) and audited with the creator
    • change_password with a wrong current password is refused

Where

  • backend/services/access_control/access_control_service.py
  • backend/services/access_control/create_admin.py
  • tests/services/access_control/test_access_control_service.py
  • dev.py, README.md

Done when

  • All the tests above pass without a database
  • .\dev admin creates the first admin on an empty test database, and refuses on one that has users

Depends on

  • Password hashing (BB-5), #87
  • Accounts and settings data access (#17): done
Lingua principale
Python
Stelle
1
Fork
1
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Bearkat-Professionals/Software-Engineering-Project

Tutte le issue di Bearkat-Professionals/Software-Engineering-Project

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.