forked from Malarum/Password-Generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassgen.py
60 lines (48 loc) · 1.72 KB
/
passgen.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python3
import string
import random
import argparse
parser=argparse.ArgumentParser(
description = '''This is a very simple password generator. If you need a new password this is it''',
epilog = """Good luck and don't get hacked""")
parser.add_argument('-l','--lowercase', action='store_true', help='Adds lowercase letters to your password')
parser.add_argument('-u','--uppercase', action='store_true', help='Adds uppercase letters to your password')
parser.add_argument('-n','--numbers', action='store_true', help='Adds numbers to your password')
parser.add_argument('-s','--special', action='store_true', help='Adds special characters to your password')
parser.add_argument('-a', '--all', action='store_true', help='Use all of the above')
args=parser.parse_args()
chars = ''
if args.all:
chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation
else:
if args.lowercase:
chars += string.ascii_lowercase
if args.uppercase:
chars += string.ascii_uppercase
if args.numbers:
chars += string.digits
if args.special:
chars += string.punctuation
def password_calculator():
while True:
pwdstr = ''
try:
password = int(input("Enter the length of the password you would like, up to 50 characters: "))
while password > 0 and password < 50:
for i in range(password):
pwdstr += random.choice(chars)
return pwdstr
break
if password > 50:
print("Please select a number between 0-50")
continue
elif password <= 0:
print("Please select a number between 1 and 50")
continue
print(pwdstr)
except ValueError:
print("that is not a number. please try again.")
else:
break
password = password_calculator()
print(password)