'secrets' module in Python.

devkant21

Devkant Swargiary

Posted on November 23, 2021

'secrets' module in Python.

The secrets module is useful for generating random numbers which might be used as a password, security tokens etc. for the application. It is used to prevent against modifying cookies, forgery attacks.

-
*Open the terminal and enter the command "python" *

python
Enter fullscreen mode Exit fullscreen mode

1.png

-
Import the secrets module

import secrets
Enter fullscreen mode Exit fullscreen mode

2.png

-
To generate a random string of characters

secrets.token_hex(16)
Enter fullscreen mode Exit fullscreen mode

3.png

-
** The generated 16 digit string **

4.png

The above generated secret key could be used in a web application as shown below :

5.png

Thanks for reading.

Drop in your suggestions.

Brickbats and Bouquets are welcome.

💖 💪 🙅 🚩
devkant21
Devkant Swargiary

Posted on November 23, 2021

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related