The Easist Way To Create Your Secret Key In Three Simple Steps
#4 Python Weekly
Hello there! π
In this article, you will be learning how to generate your secret key for your python projects. This is a guide for python enthusiasts; beginners and intermediate pythoneers.
Okay, Letβs begin!! πππ
First, we will be creating a project directory
Open cmd on your system:
Command Prompt, AKA cmd is a program that emulates the input field in a text-based user interface screen with the Windows graphical user interface (GUI). It can be used to execute entered commands and perform advanced administrative functions.
For windows users:
- Navigate to the search bar on the taskbar area
- Type
cmd
- Click on Command Prompt.
For mac users:
- Press Command + Space Bar on your Mac Keyboard.
- Type in
Terminal
. - When you see Terminal in the Spotlight search list, click it to open the terminal.
Create a project directory:
I will be creating it on my desktop β itβs your choice where you create yours.
For windows users:
- Type
cd desktop
- Type
mkdir secret-key
.
Mkdir is a keyword that makes file directory and secret-key is the name of the project directory.
For mac users:
Type
pwd
.Pwd stands for Print Working Directory .
Type
cd Desktop
.
CD stands for Change Directory .
- Type
mkdir secret-key
.
Mkdir stands for Make Directory.
Now that we have successfully created the project directory, letβs create our secret key π
This will be done in three easy, simple steps.
Before we start this, make sure your system has python installed. If you do not have python installed, click python.org/downloads, select system an OS (Operating System) then hit the download button. Download the latest version, it has better features.
Windows Installation:
phoenixnap.com/kb/how-to-install-python-3-w..
Mac Installation:
docs.python-guide.org/starting/install3/osx
Linux Installation:
docs.python-guide.org/starting/install3/linux
Create your Secret Key in three steps
- Type
python
and enter - Type
import secrets
and enter - Type
secrets.token_hex(16)
and enter
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.
The secrets.token_hex([nbytes=None]) return a random text string, in hexadecimal. The string has nbytes random bytes, each byte converted to two hex digits. If nbytes is None or not supplied, a reasonable default is used. In this case, nybtes is 16 so the output would be a random text string ( including alphabets and numbers).
Keep in touch:
Thanks for reading till the end β€οΈ.
You can contact me via email and/or Discord:
Email - iroegbusophia3@gmail.com
Discord - Sophyia#8929