Skip to content

Commit 06c7cef

Browse files
committed
change password generator to use secrets module for crypto-secured generation instead of random
1 parent 5cdb58b commit 06c7cef

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

ethical-hacking/password-generator/password_generator.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from argparse import ArgumentParser
2+
import secrets
23
import random
34
import string
45

@@ -34,25 +35,25 @@
3435
# generate random password with the length
3536
# of total_length based on all available characters
3637
passwords.append("".join(
37-
[random.choice(string.digits + string.ascii_letters + string.punctuation) \
38+
[secrets.choice(string.digits + string.ascii_letters + string.punctuation) \
3839
for _ in range(args.total_length)]))
3940
else:
4041
password = []
4142
# If / how many numbers the password should contain
4243
for _ in range(args.numbers):
43-
password.append(random.choice(string.digits))
44+
password.append(secrets.choice(string.digits))
4445

4546
# If / how many uppercase characters the password should contain
4647
for _ in range(args.uppercase):
47-
password.append(random.choice(string.ascii_uppercase))
48+
password.append(secrets.choice(string.ascii_uppercase))
4849

4950
# If / how many lowercase characters the password should contain
5051
for _ in range(args.lowercase):
51-
password.append(random.choice(string.ascii_lowercase))
52+
password.append(secrets.choice(string.ascii_lowercase))
5253

5354
# If / how many special characters the password should contain
5455
for _ in range(args.special_chars):
55-
password.append(random.choice(string.punctuation))
56+
password.append(secrets.choice(string.punctuation))
5657

5758
# Shuffle the list with all the possible letters, numbers and symbols.
5859
random.shuffle(password)

0 commit comments

Comments
 (0)