|
1 | 1 | fromargparseimportArgumentParser |
| 2 | +importsecrets |
2 | 3 | importrandom |
3 | 4 | importstring |
4 | 5 |
|
|
34 | 35 | # generate random password with the length |
35 | 36 | # of total_length based on all available characters |
36 | 37 | passwords.append("".join( |
37 | | - [random.choice(string.digits+string.ascii_letters+string.punctuation) \ |
| 38 | + [secrets.choice(string.digits+string.ascii_letters+string.punctuation) \ |
38 | 39 | for_inrange(args.total_length)])) |
39 | 40 | else: |
40 | 41 | password= [] |
41 | 42 | # If / how many numbers the password should contain |
42 | 43 | for_inrange(args.numbers): |
43 | | -password.append(random.choice(string.digits)) |
| 44 | +password.append(secrets.choice(string.digits)) |
44 | 45 |
|
45 | 46 | # If / how many uppercase characters the password should contain |
46 | 47 | for_inrange(args.uppercase): |
47 | | -password.append(random.choice(string.ascii_uppercase)) |
| 48 | +password.append(secrets.choice(string.ascii_uppercase)) |
48 | 49 |
|
49 | 50 | # If / how many lowercase characters the password should contain |
50 | 51 | for_inrange(args.lowercase): |
51 | | -password.append(random.choice(string.ascii_lowercase)) |
| 52 | +password.append(secrets.choice(string.ascii_lowercase)) |
52 | 53 |
|
53 | 54 | # If / how many special characters the password should contain |
54 | 55 | for_inrange(args.special_chars): |
55 | | -password.append(random.choice(string.punctuation)) |
| 56 | +password.append(secrets.choice(string.punctuation)) |
56 | 57 |
|
57 | 58 | # Shuffle the list with all the possible letters, numbers and symbols. |
58 | 59 | random.shuffle(password) |
|