-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassword-Generator.py
More file actions
43 lines (34 loc) · 1.27 KB
/
Password-Generator.py
File metadata and controls
43 lines (34 loc) · 1.27 KB
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
import random
import string
# All code indented below this line is part of the password generator.
def generate_password(min_length, numbers = True, special_characters = True):
letters = string.ascii_letters
digits = string.digits
special = string.punctuation
characters = letters
if numbers:
characters += digits
if special_characters:
characters += special
pwd = ""
meets_criteria = False
has_number = False
has_special = False
while not meets_criteria or len(pwd) < min_length:
new_char = random.choice(characters)
pwd += new_char
if new_char in digits:
has_number = True
elif new_char in special:
has_special = True
meets_criteria = True
if numbers:
meets_criteria = has_number
if special_characters:
meets_criteria = meets_criteria and has_special
return pwd
min_length = int(input("Enter the minumum length: "))
has_number = input("Do you want to have numbers (y/n)? ").lower() == 'y'
has_special = input("Do you want to have special characters (y/n)? ").lower() == 'y'
pwd = generate_password(min_length, has_number, has_special)
print("The generated password is:", pwd)