Changeset ef1c1c7 for docs/P4-Prototype/UseCase0001Implementation.md
- Timestamp:
- 09/24/26 17:43:19 (6 days ago)
- Branches:
- main
- Children:
- 0cee8ec
- Parents:
- a531b45
- File:
-
- 1 edited
-
docs/P4-Prototype/UseCase0001Implementation.md (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/P4-Prototype/UseCase0001Implementation.md
ra531b45 ref1c1c7 1 # Use-case 0001 Implementation — Register1 # Use-case 0001 Implementation - Register new account 2 2 3 **Initiating actor:** Visitor . **Source file:** `server/auth.go`, function `Register`.3 **Initiating actor:** Visitor 4 4 5 ## Scenario (implemented) 5 **Other actors:** — 6 6 7 1. **User** chooses option `[1] Register` from the anonymous menu. 7 A new person creates an account on EduBerza so that they can later log in as a 8 Trader ([UseCase0002](UseCase0002Implementation.md)). The Visitor enters a 9 username, an e-mail address, a full name and a password. The system validates the 10 input (required fields, an `@` in the e-mail, a password of at least 6 characters), 11 refuses a username or e-mail that is already registered, and stores only a SHA-256 12 hash of the password, never the password itself. A new account starts with a cash 13 balance of 0 USD; money is added later with a deposit 14 ([UseCase0003](UseCase0003Implementation.md)). 8 15 16 Original use-case description (P3): [UseCase0001](../P3-UseCaseModel/UseCase0001.md). 17 Implementation: [`server/auth.go`](../../server/auth.go), function `Register` 18 (the password hash is computed by `hashPassword` in the same file). 9 19 10 2. **System** prompts for username, email, full name and password (`server/auth.go:20-23`). 20 ## Scenario 11 21 12 3. **User** enters the values. 22 1. **Visitor** chooses `[1] Register` in the anonymous menu (types `1`). 23 2. **System** prints `-- Register --` and asks, one prompt after another, for 24 `Username:`, `Email:`, `Full name:` and `Password (min 6 chars):`. 13 25 14 4. **System** validates (empty checks, `@` in email, ≥ 6 chars in password) and then asks the database: 26 The screenshot shows steps 1–2: option `1` is chosen and the first prompt 27 (`Username:`) is waiting for input. 28 29  30 31 3. **Visitor** enters the values: `marko`, `marko@example.com`, `Marko Markovski`, 32 `secret1`. 33 4. **System** validates the input in Go, without accessing the database: 34 - username, e-mail and password must be non-empty, otherwise it prints 35 `Username, email and password are required.` and the scenario ends; 36 - the e-mail must contain `@` (see alternate flow 3a); 37 - the password must be at least 6 characters long, otherwise it prints 38 `Password must be at least 6 characters.` and the scenario ends. 39 5. **System** checks whether the username or the e-mail already exists 40 (`$1` = username, `$2` = e-mail): 15 41 16 42 ```sql 17 SELECT EXISTS( 18 SELECT 1 FROM users WHERE username = $1 OR email = $2 19 ); 43 SELECT EXISTS(SELECT 1 FROM users WHERE username = $1 OR email = $2) 20 44 ``` 21 45 22 23 5. **System** inserts the new row (password hashed in Go, not in SQL, to keep hashing identical between register and login): 46 If the result is `true`, alternate flow 5a applies. 47 6. **System** creates the account (`$1` = username, `$2` = e-mail, `$3` = full name, 48 `$4` = password hash). The hash is computed in Go by `hashPassword` as the 49 hex-encoded SHA-256 of the password — the same value that P3's 50 `encode(digest($4, 'sha256'), 'hex')` would produce in SQL. Hashing on the Go side 51 keeps it identical to the check done at login (SQL as in the code, only the Go 52 source indentation removed): 24 53 25 54 ```sql 26 55 INSERT INTO users (username, email, full_name, password_hash, available_balance) 27 VALUES ($1, $2, $3, $4, 0) ;56 VALUES ($1, $2, $3, $4, 0) 28 57 ``` 29 58 30 6. **System** confirms: `Account created. You can now log in.` 59 7. **System** prints `Account created. You can now log in.` and returns to the 60 anonymous menu; the Visitor can continue with 61 [UseCase0002](UseCase0002Implementation.md). 31 62 32  63 The screenshot shows steps 3–7 of the successful attempt (bottom half): the 64 entered values, the confirmation and the anonymous menu again. The top half is the 65 earlier rejected attempt from alternate flow 3a. 66 67  68 69 All statements are run on the `project` schema: the connection sets 70 `search_path=project,public` (`server/db/db.go`), so `users` means `project.users`. 71 72 ### Alternate flow 3a — invalid e-mail 73 74 In step 3 the Visitor entered `marko.example.com` (no `@`). The check in step 4 75 fails, the system prints `Invalid email.` and no SQL statement is executed. In the 76 prototype the system then shows the anonymous menu again and the Visitor chooses 77 `[1] Register` once more, which returns the scenario to step 2. 78 79  80 81 ### Alternate flow 5a — duplicate username or e-mail 82 83 After `marko` has been created, the Visitor tries to register again with username 84 `marko`, e-mail `other@example.com`, full name `Marko Two`, password `secret2`. The 85 query from step 5 (`$1` = `marko`, `$2` = `other@example.com`) returns `true` 86 because the username is taken, so the system prints 87 `Username or email already taken.`, does not run the `INSERT`, and the scenario 88 ends in the anonymous menu. 89 90  33 91 34 92 ## How to reproduce … … 37 95 ./eduberza -init # optional: reset to a known state 38 96 ./eduberza 39 # choose [1] Register, then enter username / email / full name / password 97 # [1] Register: marko / marko.example.com / Marko Markovski / secret1 -> Invalid email. 98 # [1] Register: marko / marko@example.com / Marko Markovski / secret1 -> Account created. 99 # [1] Register: marko / other@example.com / Marko Two / secret2 -> Username or email already taken. 40 100 ``` 41 101 42 The screenshot above is from an actual run: registering `marko` / 43 `marko@example.com`, followed by the confirmation line. 102 All three screenshots come from one real run of exactly these inputs.
Note:
See TracChangeset
for help on using the changeset viewer.
