Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bug fix: Added password_validator_fixed.py with proper uppercase and …
…lowercase validation
  • Loading branch information
gouriphadnis0301 committed Sep 30, 2025
commit a383cfd6a064e20a1b62d5b87acb2106fa80dc99
52 changes: 52 additions & 0 deletions password_validator_fixed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import string

def passwordValidator():
"""
Validates passwords to match specific rules
: return: str
"""
# display rules that a password must conform to
print('\nYour password should: ')
print('\t- Have a minimum length of 6;')
print('\t- Have a maximum length of 12;')
print('\t- Contain at least one uppercase letter;')
print('\t- Contain at least one lowercase letter;')
print('\t- Contain at least a number;')
print('\t- Contain at least a special character (such as @,+,£,$,%,*^,etc);')
print('\t- Not contain space(s).')

# get user's password
userPassword = input('\nEnter a valid password: ').strip()

# check if user's password conforms to the rules above
if not (6 <= len(userPassword) <= 12):
message = 'Invalid Password..your password should have a minimum '
message += 'length of 6 and a maximum length of 12'
return message

if ' ' in userPassword:
message = 'Invalid Password..your password shouldn\'t contain space(s)'
return message

if not any(i.isupper() for i in userPassword):
message = 'Invalid Password..your password should contain at least one uppercase letter'
return message

if not any(i.islower() for i in userPassword):
message = 'Invalid Password..your password should contain at least one lowercase letter'
return message

if not any(i in string.digits for i in userPassword):
message = 'Invalid Password..your password should contain at least a number'
return message

if not any(i in string.punctuation for i in userPassword):
message = 'Invalid Password..your password should contain at least a special character'
return message

return 'Valid Password!'


if __name__ == "__main__":
my_password = passwordValidator()
print(my_password)