DEV Community


Trying secrets (Python) to Generate Password

berviantoleo profile image Bervianto Leo Pratama Originally published at Medium on ・2 min read

How strong is it?

In my spare time, I want to explore more about Cyber Security. This time I will try how good secrets module. I use secrets.choice to generate my password. I use the recipe that is provided by Python documentation, here.

Photo by Chris Ried on Unsplash

I use small code to generate the list of my passwords and also small code to check the duplication. Here my python script to generate the code:

Here the code to check the password list:

I will try generate some numbers of password to check how strong the generated password. I think this naive method good for the first try how strong the module. If you not find any duplication in this method, doesn’t mean it is strong. You will need another method to check the strength. I will use 100, 1000, 100000, 1000000 and 1000000000 numbers of password. Let’s start!

100 passwords

You need to check the output, the output is False. It mean not have any duplication. I want to bring the execution time too, because it will bring long time for more numbers. It is also prove that I not get the wrong list when run Let’s check this out.

1000 passwords

Seems still good until 1000 password. Let’s check the another.

100000 passwords

1000000 passwords

Great! 100000 and 10000000, the number that “enough” number to test, still not bring any duplication. Let’s check the bigger number!

The 1000000000, I can’t produce now. I need to improve my code to parallel or multi-thread things. The current implementation will very long time to achieve. :( I will give you an update if I can run that.


I want to give “little” summary. We can assume that the secret module strong enough. We still need more advance method to check the method. For many data generation will update soon. Thank you for read this.

Discussion (0)

Editor guide