Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
40 changes: 28 additions & 12 deletions PASSWORD RELATED/password-validator/PASSWORD_VALIDATOR.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,49 @@ def passwordValidator():
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 an uppercase letter or a lowercase letter')
print('\t- Should not start with a number;')
print('\t- Contain at least one uppercase letter and 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

# Check length of password (6 to 12 characters)
if not(6 <= len(userPassword) <= 12):
message = 'Invalid Password..your password should have a minimum '
message = 'Invalid Password: Password should have a minimum '
message += 'length of 6 and a maximum length of 12'
return message

# Check if first character is a digit
if userPassword and not(userPassword[0].isalpha()):
message = "Invalid Password: First character should be a letter."
return message

# Check for spaces in password (Password mustn't contain any spaces)
if ' ' in userPassword:
message = 'Invalid Password..your password shouldn\'t contain space(s)'
return message
if not any(i in string.ascii_letters for i in userPassword):
message = 'Invalid Password..your password should contain at least '
message += 'an uppercase letter and a lowercase letter'
message = 'Invalid Password: Password shouldn\'t contain space(s)'
return message
if not any(i in string.digits for i in userPassword):
message = 'Invalid Password..your password should contain at least a number'

# Check for at least 1 upper case and 1 lower case letter in password
if not (any(c.islower() for c in userPassword) and any(c.isupper() for c in userPassword)):
message = "Invalid Password: Password should contain both uppercase and lowercase letters."
return message

# Check for at least 1 digit in password
if not any(c.isdigit() for c in userPassword):
message = 'Invalid Password: Password should contain at least one number.'
return message

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

# If no condition fails - password considered to be valid
return 'Valid Password!'

my_password = passwordValidator()
print(my_password)
9 changes: 5 additions & 4 deletions PASSWORD RELATED/password-validator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
This program validates passwords to match specific rules. A valid password is one that conforms to the following rules:
- Minimum length is 6;
- Maximum length is 12;
- Contains at least an uppercase letter or a lowercase letter
- Contains at least a number;
- Contains at least a special character (such as @,+,£,$,%,*^,etc);
- Doesn't contain space(s).
- Must not start with a number
- Contains at least one uppercase letter and one lowercase letter
- Contains at least one number;
- Contains at least one special character (such as @,+,£,$,%,*^,etc);
- Does not contain space(s).

# Prerequisites

Expand Down
Loading