

Besides another occurrence of the previous bug (no special char), there are obviously too many letters. I tried generating a password with 0 letter, 1 digit and 1 special char and got: tNpoQQ7XQtxcortvERSypXphvNNcWxryttrpfpMyhhfoXpBoBcBBxP. This happens because you first generate an alphabet with the expected number of each character type, then generate the final password by sampling repeatedly that alphabet, instead of generating the final password directly. Another try gave 54j5614: no special character and 6 digits. I tried generating a password with 1 letter, 5 digits and 1 special character and got 2$32$23: no letter and 2 special characters. There are multiple bugs in your code caused by improper logic.

The secrets module works similarly to random, but is cryptographically secure.
#Coding a strong password generator generator
The pseudo-random number generator implemented by random doesn't provide a truly random output and provides a predictable output, and as such isn't suited for password generation. For security or cryptographic uses, see the secrets module. Warning: The pseudo-random generators of this module should not be used for security purposes. Quoting from the documentation for random: Password.append(random.choice(special_list))įinalpassword.append(random.choice(password)) Password.append(random.choice(digits_list)) Password.append(random.choice(letters_list)) Many_special = int(input(f"how many special chars ? \n"))

Many_digit = int(input(f"how many digits ? \n")) Many_letter = int(input(f"how many letter ? \n")) I have written a python program for random password generation and as a newbie I would like my code to be reviewed by professionals and if they have any suggestions to improve it.
