Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Password checker
#1
Hi i'm getting a little confused with the strength checker i may be completely off here but can someone explain how to get the strength checker to work. Thanks :)

import re
def pword(password):
      

       if len(password) <=10:
               print("Your password must be 10 characters long.")
               return False
       elif not re.findall(r'\d+', password):
               print("You need a number in your password.")
               return False
       elif not re.findall(r'[A-Z]+', password):
               print("You need a capital letter in your password.")
               return False
           
       elif not re.findall(r'[|\"|\'|~|!|@|#|$|%|^|&|*|(|)|_|=|+|\||,|.|/|?|:|;|[|]|{\}|<|>]', password):
               print("You need a symbol in your password.")
               return False
       else:
               print("Password Accepted")
               return True

passwordValid = False
while not passwordValid:
   password = input("Type in your password: ")
   passwordValid = pword(password)

def passStrength():
       

       a = '[A-Z]'

       b = '[|\"|\'|~|!|@|#|$|%|^|&|*|(|)|_|=|+|\||,|.|/|?|:|;|[|]|{\}|<|>]'

       c = '\d+'

       d = '[a-z]'

       veryStrongPass = a and b and c and d
       
       strongPass =  a and b and c or b and c and d or a and c and d

       medPass = a and b or a and c or a and d or b and d or c and d

       weakPass = a or b or c or d

       

       if weakPass:

               print("Your password is weak!")

              
       elif medPass:

               print("Your password is medium!")


       elif strongPass:

               print("Your password is strong !")

               
       elif veryStrongPass:

               print("Your password is very strong !")

passStrength()
Reply
#2
Well, you can use string module and set intersection to see if a symbol is presented in the password.
In [1]: import string

In [2]: string.digits
Out[2]: '0123456789'

In [3]: string.ascii_lowercase
Out[3]: 'abcdefghijklmnopqrstuvwxyz'

In [4]: string.ascii_uppercase
Out[4]: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

In [5]: digits = set(string.digits)

In [6]: lower, upper = set(string.ascii_lowercase), set(string.ascii_uppercase)

In [7]: passwd = 'puwhwpfuhw'

In [8]: if digits & set(passwd):
   ...:     print('OK')
   ...: else:
   ...:     print('bad')
   ...:     
bad
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
(Jul-17-2017, 08:25 AM)sammy2938 Wrote:
def passStrength():
       a = '[A-Z]'
       b = '[|\"|\'|~|!|@|#|$|%|^|&|*|(|)|_|=|+|\||,|.|/|?|:|;|[|]|{\}|<|>]'
       c = '\d+'
       d = '[a-z]'
       veryStrongPass = a and b and c and d
       strongPass =  a and b and c or b and c and d or a and c and d
       medPass = a and b or a and c or a and d or b and d or c and d
       weakPass = a or b or c or d
 
       if weakPass:
                print("Your password is weak!")
       elif medPass:
                print("Your password is medium!")
       elif strongPass:
                print("Your password is strong !")
       elif veryStrongPass:
                print("Your password is very strong !")
You never actually check the password, all you do is check if a couple strings are non-empty, while it looks like your intention is probably to use those strings as regular expressions and run them against some input that isn't provided.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Simple Password Checker Dexty 8 5,071 Sep-24-2021, 06:49 PM
Last Post: deanhystad
  Variable not defined in password checker DAS 4 4,586 Aug-27-2017, 08:40 PM
Last Post: ichabod801
  Email Checker with IMAPlib ronaldrios 1 3,817 Jun-23-2017, 04:03 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020