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
53 changes: 29 additions & 24 deletions PASSWORD RELATED/password-validator/PASSWORD_VALIDATOR.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,44 @@
def passwordValidator():
"""
Validates passwords to match specific rules
: return: str
: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 an uppercase letter or a lowercase letter')
print('\t- Contain at least an uppercase letter;')
print('\t- Contain at least a 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

# Length check
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
return 'Invalid Password..length must be between 6 and 12'

# No spaces allowed
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'
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
else:
return 'Valid Password!'
return 'Invalid Password..shouldn\'t contain spaces'

# Uppercase letter check
if not any(i.isupper() for i in userPassword):
return 'Invalid Password..should contain at least one uppercase letter'

# Lowercase letter check
if not any(i.islower() for i in userPassword):
return 'Invalid Password..should contain at least one lowercase letter'

# Number check
if not any(i.isdigit() for i in userPassword):
return 'Invalid Password..should contain at least one number'

# Special character check
if not any(i in string.punctuation for i in userPassword):
return 'Invalid Password..should contain at least one special character'

return 'Valid Password!'

my_password = passwordValidator()
print(my_password)
print(my_password)
47 changes: 47 additions & 0 deletions PASSWORD RELATED/password-validator/password_validator_fixed.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

import string

def passwordValidator():
"""
Validates passwords to match specific rules
:return: str
"""
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;')
print('\t- Contain at least a 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).')

userPassword = input('\nEnter a valid password: ').strip()

# Length check
if not(6 <= len(userPassword) <= 12):
return 'Invalid Password..length must be between 6 and 12'

# No spaces allowed
if ' ' in userPassword:
return 'Invalid Password..shouldn\'t contain spaces'

# Uppercase letter check
if not any(i.isupper() for i in userPassword):
return 'Invalid Password..should contain at least one uppercase letter'

# Lowercase letter check
if not any(i.islower() for i in userPassword):
return 'Invalid Password..should contain at least one lowercase letter'

# Number check
if not any(i.isdigit() for i in userPassword):
return 'Invalid Password..should contain at least one number'

# Special character check
if not any(i in string.punctuation for i in userPassword):
return 'Invalid Password..should contain at least one special character'

return 'Valid Password!'

my_password = passwordValidator()
print(my_password)
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)