Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

python
communitycreator

How to calculate password strength using Python

Harsh Jain

Introduction

In this shot, we are going to learn how to build a password estimator that will help you to determine if your password is secure.

We will be using the zxcvbn package to build our password estimator. So, let’s get started.

To install the package, run the command below:

pip install zxcvbn

The zxcvbn package is a Python implementation of the original JavaScript library that was written and implemented by the team at Dropbox.

The original library can be found here.

Below are some points that you should know before using this package:

  • It provides an output score between 0 (terrible) to 4 (great) that is used to suggest whether or not the password should be used.
  • It provides feedback and suggestions to improve upon your password.
  • It provides the time it takes in different situations to guess the password.

Now, let’s move on to the code.

from zxcvbn import zxcvbn

first_password = zxcvbn('cZh34Jlk@139')
print(first_password)

second_password = zxcvbn('JohnRay123', user_inputs = ['John', 'Ray'])
print(second_password)
Calculate password strength using Python

Explanation:

  • On line 1, we import the required package.
  • On line 3, we pass the password to the instance of zxcvbn.
  • On line 4, we print the estimator for the password given in the above step. As you can see, the password score comes out to be 4, which means that the password is secure and can be used.
  • On line 6, we pass another password to the instance of zxcvbn. This time, we also pass the user_inputs that are provided by the user while cracking the password.
  • On line 7, we print the estimator for the second password given in the step above. As you can see, the password score comes out to 2, which means this password is not secure and should not be used. Also, we can see that there are some suggestions given by the estimator to improve our password.

In this way, we can check the strength of our password using Python.

RELATED TAGS

python
communitycreator
RELATED COURSES

View all Courses

Keep Exploring