Skip to content

Instantly share code, notes, and snippets.

@ehedaoo
Created May 25, 2017 03:56
Show Gist options
  • Save ehedaoo/54f4e8651aaf186adb56e1d47b7e1445 to your computer and use it in GitHub Desktop.
Save ehedaoo/54f4e8651aaf186adb56e1d47b7e1445 to your computer and use it in GitHub Desktop.
Generate Random Password
# Write a password generator in Python.
# strong passwords have a mix of lowercase letters, uppercase letters, numbers, and symbols.
# The passwords should be random, generating a new password every time the user asks for a new password.
# Include your run-time code in a main method.
import string
import random
characters = string.ascii_letters
chartest = [characters[i] for i in range(len(characters))]
digits = string.digits
special = string.punctuation
randomValue = characters + digits + special
def createpassword(randomValue, passlen):
password = ''.join(random.sample(randomValue, passlen))
return password
def mainstart():
passlen = int(input("Enter the length of your password greater than 6: "))
if passlen < 6:
print("Password should be greater than 6. Retry!")
mainstart()
else:
password = createpassword(randomValue, passlen)
print(password)
reqagain = input("Want to try again? Y/N ").lower()
if reqagain == 'y':
mainstart()
else:
quit()
mainstart()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment