| title | tags | |||||
|---|---|---|---|---|---|---|
Password Strength Validator |
|
Write a function that evaluates the strength of a given password based on specific criteria.
The password must satisfy all the following conditions:
- Password should have at least 8 characters
- Password should contain at least one uppercase letter
- Password should contain at least one lowercase letter
- Password should contain atleast one digit
- Password should contain at least one special character from: @#$%^&*
Input Format: A single string representing the password
Output Format: A tuple containing (boolean, list) where:
- boolean indicates if the password meets all criteria (True/False)
- list contains feedback number for the unmet criteria (empty list if all criteria are met)
Sample Input
Hello123@
Sample Output
(True, [])
<prefix>
def check_password_strength(password: str) -> tuple:
'''
Evaluate password strength based on given criteria.
Returns (True, []) if password is strong,
(False, feedback) if criteria not met.
'''
</prefix>
<template>
feedback = []
<sol>
if len(password) < 8:
feedback.append(1)
if not any(c.isupper() for c in password):
feedback.append(2)
if not any(c.islower() for c in password):
feedback.append(3)
if not any(c.isdigit() for c in password):
feedback.append(4)
special_chars = "@#$%^&*"
if not any(c in special_chars for c in password):
feedback.append(5)
if feedback:
return (False, feedback)
return (True, [])
</sol>
<los>pass</los>
</template>
<suffix>
password = input().strip()
result = check_password_strength(password)
print(result)
</suffix>Hello123@
(True, [])
hello123
(False, [2, 5])
Ab1@defgh
(True, [])
Ab1
(False, [1, 5])
HELLO123@
(False, [3])
HelloWorld#1
(True, [])