Python temporary password rule check
2025-hsc-se-q19 · Code Response · 3 marks
Source: NESA 2025 HSC Software Engineering HSC Q19
Question
In an organisation, temporary passwords are automatically generated for new user
accounts. Each password is created from the first three letters of the username followed
by 123.
For example, the username NESA will have the password NES123.
When a user logs in for the first time, they are asked for their username and password. They receive a welcome message or an error message, depending on whether the password entered follows the rules of new user accounts.
Write a Python program that asks a new user for their username and password, and then checks whether the password rule has been followed.
Response
Reveal answer
username = input("What is your username? ")
password = input("What is your password? ")
expected_password = username[:3] + "123"
if expected_password == password:
print("Welcome!")
else:
print("Incorrect password entered")
Marking rubric
| Marks | Description |
|---|---|
| 3 | Provides correct code for the problem. |
| 2 | Provides partially correct code that includes a correct selection structure or password creation. |
| 1 | Shows some understanding of the scenario and Python programming. |
Explanation
The program needs to create the expected password from the first three characters of the
username, append 123, then compare this with the entered password.
Metadata
- Submitter
- Seed data
- Created
- 2026-05-02
- Status
- published
- Syllabus
- y12-project-design-construct-implement-solution
- Tags
- Python strings selection password validation