Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #### ITERATION DEF ####
- def is_password_valid(password):
- length_ok = len(password) > 7
- lowercase_ok = any(c.islower() for c in password)
- uppercase_ok = any(c.isupper() for c in password)
- number_ok = any(c.isdigit() for c in password)
- return sum([length_ok, lowercase_ok, uppercase_ok, number_ok]) == 4
- #### ITERATION 1 ####
- import string
- password = "dfshtj54aA"
- lowercase = {x for x in string.ascii_lowercase}
- uppercase = {x for x in string.ascii_uppercase}
- numbers = {str(x) for x in range(0, 10)}
- length_ok = len(password) > 7
- lowercase_ok = len(lowercase.intersection(password)) > 0
- uppercase_ok = len(uppercase.intersection(password)) > 0
- number_ok = len(numbers.intersection(password)) > 0
- if length_ok and lowercase_ok and uppercase_ok and number_ok:
- print("Password ok")
- else:
- print("Password not ok")
- #### ITERATION 2 ####
- password = "dfshtj54aA"
- lowercase_ok = len(set(string.ascii_lowercase).intersection(password)) > 0
- uppercase_ok = len(set(string.ascii_uppercase).intersection(password)) > 0
- number_ok = len({str(x) for x in range(0, 10)}.intersection(password)) > 0
- result = "Password ok" if (len(password) > 7) + lowercase_ok + uppercase_ok + number_ok == 4 else "Password not ok"
- print(result)
- #### ITERATION 3 aka VALLIONXD ####
- password = "dfshtjd4aDa"
- lowercase_ok = any(c.islower() for c in password)
- uppercase_ok = any(c.isupper() for c in password)
- number_ok = any(c.isdigit() for c in password)
- result = "Password ok" if (len(password) > 7) + lowercase_ok + uppercase_ok + number_ok == 4 else "Password not ok"
- print(result)
- #### ITERATION 4 QUITE UGLY ####
- password = "dfshtjdaGa"
- pwd = [ord(c) for c in password]
- print("Password ok" if (len(pwd) > 7) and (47 < min(pwd) < 58) and (96 < max(pwd) < 123)
- and any(c.isupper() for c in password) else "Password not ok")
Advertisement
Comments
-
- ###################### EVEN SHORTER ONE #################################
- import string; print('Password ok' if len('dfshtj54aA') > 7 and any(c.islower() for c in 'dfshtj54aA') and any(c.isupper() for c in 'dfshtj54aA') and any(c.isdigit() for c in 'dfshtj54aA') else 'Password not ok')
-
- Yes, *any* is a very good idea. Readability counts so i would prefer the first one with any. :)
- lowercase_ok = any(c.islower() for c in password)
- etc.
Add Comment
Please, Sign In to add comment
Advertisement