Home python Check Password for Difficulty

Check Password for Difficulty

Author

Date

Category

I want to make a program for checking the complexity of the password that enters the user, but I do not know how to register the logic of checking the complexity of the password (check for the content of the letters of different registers, numbers, various specials. characters, etc.), and after checking Receive the result: Reliable password or not.

Here is a small piece of code:

label_1 = label (window, text = "Enter the password for checking")
Label_1.grid (column = 0, row = 0)
TXT_PASSWORD = ENTRY (Window, width = 10)
TXT_PASSWORD.Grid (column = 1, row = 0)
Def clicked ():
  # Check for password complexity
  Pass
BTN = Button (Window, Text = "Check", Command = Clicked)
Window.Mainloop ()

Answer 1, Authority 100%

import re
DEF PCheck (A: STR) - & gt; Str:
  Res = [Re.Search (R "[AZ]", a), Re.Search (R "[AZ]", a), Re.Search (R "[0-9]", a), Re.Search (R "\ w", a)]
  IF All (RES):
    RETURN "PASSWORD IS OKAY"
  Return ("Password IS WEAK. Add" +
      "LowerCase Letters," * (Res [0] is none) +
      "Uppercase Letters," * (Res [1] is none) +
      "Digits," * (Res [2] is none) +
      "Special Symbols," * (Res [3] IS NONE) +
       "Then Try Again")

Check:

print (PCheck ("12a3w @ Mya"))
Print (PCheck ("123w"))
Print (PCheck ("123w"))
Print (PCheck ("AWME"))
Print (PCheck ("@ #"))

What will give out respectively:

Password is Okay
Password is weak. Add LowerCase Letters, Special Symbols, Then Try Again
Password is weak. Add Uppercase Letters, Special Symbols, Then Try Again
Password is weak. Add Digits, Special Symbols, Then Try Again
Password is weak. Add LowerCase Letters, Uppercase Letters, Digits, Then Try Again

Answer 2, Authority 20%

Python do not know because I write the general idea of ​​the logic of work:

  1. Write check availability in the line of capital letters.
  2. Write check availability in the string of lowercase letters
  3. Write check availability in the row of numbers
  4. Write a check of the presence in the string of characters from a given set of specialsms.
  5. If all the checks returned True Password quite complicated. If not – well, here you know what to do.

I think the functions suitable for all these checks are in standard libraries.


Answer 3, Authority 20%

This task will need to use regular expressions. And using Yuri’s answer, you can write an algorithm

import re
...
DEF Get_Strength_Point (Match):
  Return 1 If Match ELSE 0
Def clicked ():
  password = TXT_PASSWORD.get ()
  Strength_point = 0.
  # Point for length
  Strength_Point + = Get_strength_Point (Len (Password) & GT; 8)
  # Clear for the presence of numbers
  strngth_point + = get_strength_point (Re.Search (R "\ D", Password))
  # Point for the presence of upper register letters
  strngth_point + = get_strength_point (Re.Search (R "[A-Z]", Password))
  # Clear for the presence of lower register letters
  strngth_point + = get_strength_point (Re.Search (R "[A-Z]", Password))
  # Clear for presence of special characters
  strngth_point + = get_strength_point (Re.Search (R "\ w, Password))
  If 0 & lt; = Strength_Point & LT; 2:
    Return 'Easy Password'
  ELIF 2 & LT; = Strength_point & lt; 4:
    Return 'Middle Password'
  ELSE:
    Return 'Difficult Password'
...

Answer 4, Authority 20%

There is an excellent module for checking the complexity of the password:

password_strength

Here is a link to a similar question with ENSO:
Checking the Strength of A Password (How to Check Conditions)

PIP3 Install Password_strength

from password_strength import passwordstats 
...
Label_1 = label (Window, Text = "Enter the password for checking")
Label_1.grid (column = 0, row = 0)
TXT_PASSWORD = ENTRY (Window, width = 10)
TXT_PASSWORD.Grid (column = 1, row = 0)
Def clicked ():
  STATS = PasswordStats (TXT_PASSWORD.GET ())
  If stats.strength () & gt; 0.5:
    Label_1.configure (Text = "Good Password")
  ELSE:
    Label_1.configure (Text = "Bad Password")
BTN = Button (Window, Text = "Check", Command = Clicked)
Window.Mainloop ()

Answer 5

Guys, if we talk about the actual password check for complexity, then the main thing here is the length of the password. And the person is able to enter as a password for example:

“How many discoveries of wonderful
Prepares enlightenment spirit!
And experience, son of mistakes difficult,
And genius, paradoxes friend. “

Believe me, watching such a password much more difficult than your 8 characters “12a3w @ m.”
So it is not starting, gentlemen, if the password length is not a word. 🙂
Well, or password out of 5 characters to consider “complex”

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions