Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random, re
- a = 0
- password = ''
- while a < 8:
- if random.randint(0, 61) < 10:
- password += chr(random.randint(48, 57))
- elif 10<random.randint(0, 61)<36:
- password += chr(random.randint(65, 90))
- else:
- password += chr(random.randint(97, 122))
- a += 1
- print(password)
- ## OUTPUT: t1fGf4Ha
- #divide the 8 character to 2 part. first 3 and last 5.
- print(password[:3])
- ## OUTPUT: t1f
- print(password[3:])
- ## OUTPUT: Gf4Ha
- #make sure in the first part all 3 kinds of character are being used
- def password_check(password):
- # calculating the length
- length_error = len(password) < 8
- # searching for digits
- digit_error = re.search(r"\d", password) is None
- # searching for uppercase
- uppercase_error = re.search(r"[A-Z]", password) is None
- # searching for lowercase
- lowercase_error = re.search(r"[a-z]", password) is None
- # overall result
- password_ok = not ( length_error or digit_error or uppercase_error or lowercase_error)
- return password_ok
- password_check(password)
- #suffle
- if password_check(password) == True:
- new_pwd = ''.join(random.sample(password,len(password)))
- print new_pwd
- # OUTPUT: G1ft4afH
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement