Skip to main content

Command Palette

Search for a command to run...

'secrets' module in Python.

Updated
1 min read
D

Full Stack Developer. I have hands on experience in crafting web applications using TypeScript, Next , React ,TailwindCSS. I have also worked with PostgresDB and AWS S3. I have also developed dAPP based upon ERC 20 , ERC 721 tokens.

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

1.png

- Import the secrets module

import secrets

2.png

- To generate a random string of characters

secrets.token_hex(16)

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.