Write a password generator in Python. Be creative with how you generate passwords - 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 code in a main method.
Extra:
There are so many possible solutions to this exercise, really depending on how far you want to challenge yourself. The field of security, especially as it relates to computing, is an ever-growing field with countless experts, theories, principles, and more.
The sample solution here is one possible way to answer the question: it generates a string of random characters. It is clean, simple, and elegant.
# generate a password with length "passlen" with no duplicate characters in the password | |
import random | |
s = "abcdefghijklmnopqrstuvwxyz01234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?" | |
passlen = 8 | |
p = "".join(random.sample(s,passlen )) | |
print p |
And here is another, using internal Python functions:
import string | |
import random | |
def pw_gen(size = 8, chars=string.ascii_letters + string.digits + string.punctuation): | |
return ''.join(random.choice(chars) for _ in range(size)) | |
print(pw_gen(int(input('How many characters in your password?')))) |