Skip to content

Instantly share code, notes, and snippets.

@KHerb
Last active November 20, 2016 01:58
Show Gist options
  • Save KHerb/47ad6927f4abe7f829cc16b9138aa459 to your computer and use it in GitHub Desktop.
Save KHerb/47ad6927f4abe7f829cc16b9138aa459 to your computer and use it in GitHub Desktop.
Password generator, password checker and more!
import random
def pwgenerator():
lower = 'abcdefghijklmnopqrstuvwxyz'
up = lower.upper()
special = "~!@#$%^&*()_-+=}{|[]\?/:;'<>,."
password = ""
for i in range(3):
password += random.choice(lower)
password += random.choice(up)
password += random.choice(special)
return password
pwg = pwgenerator()
print "Welcome to Password Generator 1.0!\nHere is your temporary password:" ,pwg
def password():
x = raw_input("Enter your password: ")
z = '1234567890'
y = 'abcdefghijklmnopqrstuvwxyz'
w = y.upper()
special = "~!@#$%^&*()_-+=}{|[]\?/:;'<>,."
if len(x)>9:
if any([c in z for c in x]):
if any([c in y for c in x]):
if any ([c in w for c in x]):
if any ([c in special for c in x]):
print "Your password has been changed to < %s >" % x
else:
print "Does your password contain a special charcater? (~!@#$%^&*()_-+=}{|[]\?/:;'<>,.)"
password()
else:
print "Does your password contain an uppercase letter?"
password()
else:
print "Does your password contain a lowercase letter?"
password()
else:
print "Does your password contain a number?"
password()
else:
print "Is your password at least 9 characters long?"
password()
def pwchecker():
user = raw_input("Please enter your temporary password: ")
attempts = 0
while attempts < 3:
if user != pwg:
user = raw_input("Incorrect. Please enter it again: ")
attempts += 1
elif user == pwg:
print "Your new password must be at least 9 characters long, contain an uppercase/lowercase letter, at least one number and a special character."
password()
break
else:
print "Too many incorrect entries!"
personal = raw_input("Would you like to change your password? (y/n) ")
while personal != 'y' and personal != 'n':
personal = raw_input("Sorry, what was that? (y/n)")
if personal == 'y':
pwchecker()
elif personal == 'n':
print "Your password will still be " ,pwg + " the next time you log in"
@g3nz0d-zz
Copy link

Nice. I'm learning PY myself, so a lot of this elements here are unknown to me. Do you have a whitepaper or write-up? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment