-
Notifications
You must be signed in to change notification settings - Fork 28
/
pass_generator.py
51 lines (39 loc) · 1.46 KB
/
pass_generator.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
import random
import string
def main():
print("_____________________________________")
print("| Welcome to this Password Generator |")
print("-------------------------------------\n")
try:
length = int(
input("how long do you want your password to be (minimum of 8 number)")
)
except:
print("Input numners only")
password_length = 0
while password_length < length:
print("Your password must have at least 8 characters")
password_length = getPasswordLength()
all_characters = getCharacters()
password = generatePassword(all_characters, password_length)
print("\nYour password is: " + password)
print("__________________________________________")
print("| Thanks for using the Password Generator |")
print("------------------------------------------")
def getPasswordLength():
# Set the password length with constraints for the password length
password_length = int(input("\nEnter the length of password: "))
return password_length
def getCharacters():
# define the characters
lower = string.ascii_lowercase
upper = string.ascii_uppercase
num = string.digits
symbols = string.punctuation
all_characters = lower + upper + num + symbols
return all_characters
def generatePassword(all_characters, password_length):
# generate a password string
password = "".join(random.sample(all_characters, password_length))
return password
main()