The PasswordChecker class currently has a bug in the check_strength function, where it only checks if the first character of the password is a digit. This leads to incorrect strength scoring when passwords contain digits in any position other than the first.
1) Initialize the PasswordChecker class.
2) Run the check_strength method with a password that contains numbers not at the start, e.g., "weakpass2".
3) Observe that the feedback suggests the password lacks a number, despite containing one.
Expected Behavior
The check_strength function should correctly identify numbers anywhere in the password and adjust the strength score and feedback accordingly.
Actual Behavior
The function only checks if the first character is a digit. If the number is placed elsewhere in the password, the feedback incorrectly states that a number is missing.
Tasks
[ ] Modify the number-checking condition in the check_strength method to check for digits anywhere in the password.
[ ] Update any affected tests or add new ones if needed.
Possible Fixes
Replace if password[0].isdigit() with if any(c.isdigit() for c in password) to properly check for digits throughout the entire password.
Description
The PasswordChecker class currently has a bug in the check_strength function, where it only checks if the first character of the password is a digit. This leads to incorrect strength scoring when passwords contain digits in any position other than the first.
Files
password_checker.py
To Reproduce
1) Initialize the PasswordChecker class. 2) Run the check_strength method with a password that contains numbers not at the start, e.g., "weakpass2". 3) Observe that the feedback suggests the password lacks a number, despite containing one.
Expected Behavior
The check_strength function should correctly identify numbers anywhere in the password and adjust the strength score and feedback accordingly.
Actual Behavior
The function only checks if the first character is a digit. If the number is placed elsewhere in the password, the feedback incorrectly states that a number is missing.
Tasks
Possible Fixes
Replace if
password[0].isdigit()
withif any(c.isdigit() for c in password)
to properly check for digits throughout the entire password.