• Latest
  • Trending
How to Encrypt a Password in Python Using bcrypt

How to Encrypt a Password in Python Using bcrypt

February 22, 2022
Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023
Vice President Dr. Bawumia inaugurates  ICT Hub

Vice President Dr. Bawumia inaugurates ICT Hub

April 2, 2023
Co-Creation Hub’s edtech accelerator puts $15M towards African startups

Co-Creation Hub’s edtech accelerator puts $15M towards African startups

February 20, 2023
Data Leak Hits Thousands of NHS Workers

Data Leak Hits Thousands of NHS Workers

February 20, 2023
EU Cybersecurity Agency Warns Against Chinese APTs

EU Cybersecurity Agency Warns Against Chinese APTs

February 20, 2023
How Your Storage System Will Still Be Viable in 5 Years’ Time?

How Your Storage System Will Still Be Viable in 5 Years’ Time?

February 20, 2023
The Broken Promises From Cybersecurity Vendors

Cloud Infrastructure Used By WIP26 For Espionage Attacks on Telcos

February 20, 2023
Instagram and Facebook to get paid-for verification

Instagram and Facebook to get paid-for verification

February 20, 2023
YouTube CEO Susan Wojcicki steps down after nine years

YouTube CEO Susan Wojcicki steps down after nine years

February 20, 2023
Inaugural AfCFTA Conference on Women and Youth in Trade

Inaugural AfCFTA Conference on Women and Youth in Trade

September 6, 2022
  • Consumer Watch
  • Kids Page
  • Directory
  • Events
  • Reviews
Friday, 17 July, 2026
  • Login
itechnewsonline.com
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion
Subscription
Advertise
No Result
View All Result
itechnewsonline.com
No Result
View All Result

How to Encrypt a Password in Python Using bcrypt

Follow this tutorial to learn bcrypt from installation to encryption.

by ITECHNEWS
February 22, 2022
in Data Science, Leading Stories
0 0
0
How to Encrypt a Password in Python Using bcrypt

Password encryption masks users’ passwords so they become hard to guess or decode. It’s an essential step in developing secure user-base software. Whether you’re building one with Flask or another light Python Framework, you can’t ignore that step. That’s where bcrypt comes in.

We’ll show you how to use bcrypt to hash your password in Python.

YOU MAY ALSO LIKE

French Telco Orange Hit by Cyber-Attack

ATC Ghana supports Girls-In-ICT Program

How bcrypt Works

Bcrypt is a language-agnostic hashing library that offers unique password encryption. While encrypting your string, it generates extra random characters (salt) by default to beef up the security of your password.

Optionally, you can also specify the number of extra characters you want to add to an incoming string.

The bcrypt library doesn’t read raw strings—byte code only. So to start, you’ll first encode an incoming password string before passing it to bcrypt for encrypting.

Encoding isn’t the same as encrypting. It only ensures that a string becomes machine-readable before an encryption algorithm can mask it.

Encrypting a Password in Python With bcrypt

bcrypt password encryption is easy with Python. We’ll focus on how to do this without using a framework. But no worries, it follows the same process in frameworks once you know how to store your users’ inputs and read them from the database.

Install and Set Up bcrypt

If you haven’t done so already, activate a Python virtual environment in your project root. Then install bcrypt using pip:

Start Encrypting Passwords

Once installed, let’s see how to encrypt a string using bcrypt:

When you run the Python code above, it prints an encrypted byte string. The output, however, changes each time you execute the script. This is how bcrypt ensures each user has a uniquely encrypted password.

That’s for password encryption, by the way.

How to Compare and Confirm Passwords With bcrypt

What if you want to store the hashed password and confirm later that it matches a user’s provided password during authentication?

That’s easy. You only need to compare the authenticating password with the one stored in the database (or in memory in this case).

And since bcrypt only reads byte strings, you’ll also need to encode the authenticating password before comparing it with the one in the database. In essence, you’ll cross-check an encoded authentication input with the encoded hashed password already stored in your database.

Using dummy Python inputs, let’s see how this works in practice:

The above code asks you to input a new password when you execute it. Python stores this in memory. You’ll then provide the same password (known only to you) in the authenticating field.

Python prints a success message if the compared password matches the previously stored encrypted one. Otherwise, it outputs the failed message wrapped in the else statement:

The whole concept is the same as storing a password in a database during registration and providing it later during authentication.

Scale Up Encryption With bcrypt

While we’ve only demonstrated how bcrypt works by storing encrypted passwords into plain Python short memory, its ultimate usage is in real-life user-base applications.

Nonetheless, this tutorial shows the fundamental ways to structure your code to achieve this, even in real-life scenarios. For instance, if you’re using Flask, you can replace the inputs with separate web forms to serve the registration and authentication fields. And of course, you’ll store encrypted passwords in a real-life database and read from it when comparing passwords.

Source: IDOWU OMISOLA
Tags: Python Using bcrypt
ShareTweet

Get real time update about this post categories directly on your device, subscribe now.

Unsubscribe

Search

No Result
View All Result

Recent News

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025
ATC Ghana supports Girls-In-ICT Program

ATC Ghana supports Girls-In-ICT Program

April 25, 2023

About What We Do

itechnewsonline.com

We bring you the best Premium Tech News.

Recent News With Image

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa

July 29, 2025
French Telco Orange Hit by Cyber-Attack

French Telco Orange Hit by Cyber-Attack

July 29, 2025

Recent News

  • Absa and Visa Extend Strategic Partnership to Advance Growth and Innovation Across Africa July 29, 2025
  • French Telco Orange Hit by Cyber-Attack July 29, 2025
  • ATC Ghana supports Girls-In-ICT Program April 25, 2023
  • Vice President Dr. Bawumia inaugurates ICT Hub April 2, 2023
  • Home
  • InfoSec
  • Opinion
  • Africa Tech
  • Data Storage

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Welcome Back!

Login to your account below

Forgotten Password?

Retrieve your password

Please enter your username or email address to reset your password.

Log In

Add New Playlist

No Result
View All Result
  • Home
  • Tech
  • Africa Tech
  • InfoSEC
  • Data Science
  • Data Storage
  • Business
  • Opinion

© Copyright 2026, All Rights Reserved | iTechNewsOnline.Com - Powered by BackUPDataSystems

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?
Go to mobile version