The proper way to execute a loop exactly n times is: for _ in range(n): The second bug comes from the fact that when you loop over a collection ( for d in digits_list:), the code will break out of the loop before the counter reaches the specified amount. The first bug is caused because you increment the counter before checking its value, meaning that by the time you check if counter_l = many_letter, counter_l is greater than 0. This happens because of the way you handle loops, mixing for loops and manually handling a loop counter. Besides the first bug, I expected a 1002-character-long password. Now, that's way too few digits, or characters overall. Then I tried 1 letter, 1000 digits and 1 special char and got: |87b07bb17|9. 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. 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.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |