Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit06c7cef

Browse files
committed
change password generator to use secrets module for crypto-secured generation instead of random
1 parent5cdb58b commit06c7cef

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
fromargparseimportArgumentParser
2+
importsecrets
23
importrandom
34
importstring
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_inrange(args.total_length)]))
3940
else:
4041
password= []
4142
# If / how many numbers the password should contain
4243
for_inrange(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_inrange(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_inrange(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_inrange(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)

[8]ページ先頭

©2009-2025 Movatter.jp