The Secrets Module of Python

A unique module explained with some programs

Swathi Arun
The Pythoneers

--

Photo by Maxwell Nelson on Unsplash

One of the most interesting built-in modules in Python is secrets which were released in Python 3.6. It is popularly known to produce data that are close to true randomness. With the help of this package, you can produce cryptographically strong data. Some data produced with this method can be used in passwords, tokens, OTP( One Time Password). In this article, let us learn about the secrets module and its methods and how it is different from random modules.

Why is the secrets module better than the random module? Although you can generate random data from a random module, it is not non-deterministic data. Data that is produced from the random modules can be determined easily by finding the seed that is used to produce the data. Any data that can be determined cannot be considered secure data. Secrets module is an excellent secure source to produce random data.

Secrets choice Method:

A program to generate a 7 digit OTP(One Time Password) with secrets package:

This module produces data that are strong and it is from a secure source of randomness. OTP is used for some secure transactions, it is crucial to produce strong cryptographic data.

import secrets
import string

--

--

Swathi Arun
The Pythoneers

2x Top Writer || Power BI || Python || Art || Travel || Engineer || Writer|| Become a Medium Member by Clicking here: https://swathiarun63.medium.com/membership