Why you should never use random module for generating passwords.

Why Random Numbers Are Not Random?

The Random Numbers come from a particular seed number which is usually the system clock.Run the program below to understand the security risk.

The Python Documentation also has a warning about the …


This content originally appeared on DEV Community and was authored by Vaarun Sinha

Why Random Numbers Are Not Random?

The Random Numbers come from a particular seed number which is usually the system clock.Run the program below to understand the security risk.

The Python Documentation also has a warning about the same: "The pseudo-random generators of this module should not be used for security purposes."

So all the password generators you have built using random module are not secure!? So How do we generate cryptographically secure numbers/passwords?

But there is another line after that warning:
"For security or cryptographic uses, see the secrets module."

What is this secrets module?

The secrets module is used for generating cryptographically strong random numbers suitable for managing data such as passwords, account authentication, security tokens, and related secrets.

How it is different from the random module?

I found a really good post on reddit from which you can understand what is the difference between these two modules.

The Post says:

"with random your numbers come from some seed number, usually based on the system clock, which generates pseudo-random numbers. That means that if you get guess the seed, you can generate the same sequence of numbers. If you used pseudorandomly generated numbers as salts for all your passwords, then brute forcing the keys would become trivial.
true random numbers come from "high entropy" seeds, meaning it's not just some number you can guess, it's things that are impossible to reproduce algorithmically. Imagine things like keyboard inputs, time between keystrokes, mouse movements, cpu usage, number of programs running, etc. It might not use those exactly, but you can see how the numbers it generates from those sources are literally impossible to reproduce which is why you want to use those ones as your encryption keys and salts."

And another post says:

"It's more secure because it's less predictable. The random module uses an algorithm that's fast but it's possible to calculate what the next random number will be. That's fine for randomly placing things on the screen or something but for generating passwords it's important that the number is not predictable."

So basically it makes the seed really hard to guess( less predictable)

Reddit Post 1: https://www.reddit.com/r/learnpython/comments/7w8w6y/comment/dtyg7wd/?utm_source=share&utm_medium=web2x&context=3

Reddit Post 2:
https://www.reddit.com/r/learnpython/comments/7w8w6y/comment/dtyi6z8/?utm_source=share&utm_medium=web2x&context=3

Stay tuned for the next blog where we make a password generator which generates cryptographically strong passwords.

Happy Coding


This content originally appeared on DEV Community and was authored by Vaarun Sinha


Print Share Comment Cite Upload Translate Updates
APA

Vaarun Sinha | Sciencx (2021-11-04T09:43:19+00:00) Why you should never use random module for generating passwords.. Retrieved from https://www.scien.cx/2021/11/04/why-you-should-never-use-random-module-for-generating-passwords/

MLA
" » Why you should never use random module for generating passwords.." Vaarun Sinha | Sciencx - Thursday November 4, 2021, https://www.scien.cx/2021/11/04/why-you-should-never-use-random-module-for-generating-passwords/
HARVARD
Vaarun Sinha | Sciencx Thursday November 4, 2021 » Why you should never use random module for generating passwords.., viewed ,<https://www.scien.cx/2021/11/04/why-you-should-never-use-random-module-for-generating-passwords/>
VANCOUVER
Vaarun Sinha | Sciencx - » Why you should never use random module for generating passwords.. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/11/04/why-you-should-never-use-random-module-for-generating-passwords/
CHICAGO
" » Why you should never use random module for generating passwords.." Vaarun Sinha | Sciencx - Accessed . https://www.scien.cx/2021/11/04/why-you-should-never-use-random-module-for-generating-passwords/
IEEE
" » Why you should never use random module for generating passwords.." Vaarun Sinha | Sciencx [Online]. Available: https://www.scien.cx/2021/11/04/why-you-should-never-use-random-module-for-generating-passwords/. [Accessed: ]
rf:citation
» Why you should never use random module for generating passwords. | Vaarun Sinha | Sciencx | https://www.scien.cx/2021/11/04/why-you-should-never-use-random-module-for-generating-passwords/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.