-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_generator.py
43 lines (32 loc) · 1.49 KB
/
password_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
import random
import string
def generate_password(quantity_letters, quantity_digits, quantity_punctuation):
letters = string.ascii_letters
digits = string.digits
punctuation = '!@?#%'
quantity_letters = ''.join(random.choice(letters) for _ in range(quantity_letters))
quantity_digits = ''.join(random.choice(digits) for _ in range(quantity_digits))
quantity_punctuation = ''.join(random.choice(punctuation) for _ in range(quantity_punctuation))
password = quantity_letters + quantity_digits + quantity_punctuation
return password
def shuffle_password(password):
password = list(password)
random.shuffle(password)
password = ''.join(password)
print(f"Password shuffled: {password}")
return password
def write_password_to_file(password): # Write the password to a file
file_path = "password.txt"
with open(file_path, 'w') as file:
file.write(password)
return file_path
def main():
quantity_letters = int(input("Enter the quantity of letters: "))
quantity_digits = int(input("Enter the quantity of digits: "))
quantity_punctuation = int(input("Enter the quantity of punctuation: "))
password_generated = generate_password(quantity_letters, quantity_digits, quantity_punctuation)
password_shuffled = shuffle_password(password_generated)
password_file = write_password_to_file(password_shuffled)
print(f"Password sent to file: {password_file}")
if __name__ == "__main__":
main()