• We just launched and are currently in beta. Join us as we build and grow the community.

How to Check if Password is Strong or Weak in Python

Trill

Local Pack Strategist
Divine
T Rep
0
0
0
Rep
0
T Vouches
0
0
0
Vouches
0
Posts
153
Likes
199
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1 300 XP
In this tutorial, we will program "How to Check if a Password is Strong or Weak in Python." We’ll focus on validating a password to determine whether it meets the requirements for strength. The objective is to safely check if the entered password passes the necessary qualifications. A sample program will be provided to demonstrate the coding process effectively.

This topic is straightforward to understand. Just follow the instructions I provide, and you'll be able to complete it yourself with ease. The program I'll show you demonstrates the correct way to validate a password to determine if it is strong or weak. I'll also provide a simple and efficient method to achieve this effectively. So, let’s start coding!

Getting Started:

First you will have to download & install the Python IDLE's, here's the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/.

Creating Main Function

This is the main function of the application. The following code will display a simple GUI in terminal console that will display program. To do this, simply copy and paste these blocks of code into the IDLE text editor.
  1. import

    re



  2. def

    password(

    v)

    :

  3. if

    v ==

    "\n

    "

    or

    v ==

    " "

    :
  4. return

    "Password cannot be a newline or space!"

  5. if

    9

    <=

    len

    (

    v)

    <=

    20

    :


  6. if

    re

    .search

    (

    r'(.)\1

    \1

    '

    ,

    v)

    :
  7. return

    "Weak Password: Same character repeats three or more times in a row"


  8. if

    re

    .search

    (

    r'(..)(.*?)\1

    '

    ,

    v)

    :
  9. return

    "Weak password: Same string pattern repetition"

  10. else

    :
  11. return

    "Strong Password!"

  12. else

    :
  13. return

    "Password length must be 9-20 characters!"


  14. def

    main(

    )

    :
  15. while

    True

    :
  16. print

    (

    "\n

    ================= Check if Password is Strong or Weak =================\n

    \n

    "

    )
  17. mypass=

    input

    (

    "Please enter your password here: "

    )
  18. print

    (

    password(

    mypass)

    )
  19. opt =

    input

    (

    "\n

    Do you want to try again?(yes/no): "

    )

  20. if

    opt.lower

    (

    )

    ==

    'yes'

    :
  21. ret=

    False
  22. elif

    opt.lower

    (

    )

    ==

    'no'

    :
  23. ret=

    True
  24. print

    (

    "Exiting program...."

    )
  25. else

    :
  26. print

    (

    "Please enter yes/no:"

    )
  27. break

  28. if

    ret ==

    False

    :
  29. continue



  30. if

    __name__ ==

    '__main__'

    :
  31. main(

    )

This program evaluates a user-entered password for strength, marking it as "Strong" if it meets the criteria of being 9 to 20 characters long, containing no repeated characters in a row or repeated patterns, and not consisting solely of newlines or spaces. If the password fails any of these checks, it is marked "Weak," with an explanation provided. The program runs continuously, prompting the user to try again until they choose to exit.

Output:

how-to-check-if-password-is-strong-or-weak-using-python-1.jpg

There you have it we successfully created How to Check if Password is Strong or Weak in Python. I hope that this simple tutorial help you to what you are looking for. For more updates and tutorials just kindly visit this site. Enjoy Coding!

More Tutorials for Python Language

Python Tutorials


Download
You must upgrade your account or reply in the thread to view hidden text.
 

450,491

323,080

323,089

Top