sam norman
sam norman

Reputation: 17

Password Checker Python

In my password checker i dont know why when i use caps and lower case in my input it doesnt out put strong password.

enter code here
print("Password Checker")
pw=input("Enter Your Password Here: ")

if len(pw)<=5:
if pw!=pw.upper()or pw!=pw.lower():
    print("WEAK Password")
elif len(pw)>=6 and len(pw)<=12:
if pw==pw.lower():
    print("Medium Password")
elif len(pw)>=13:
    print("Too Long")
elif len(pw)<=12 and len(pw)>=6:
if pw==pw.upper() and pw==pw.lower():
    print("Thats A STRONG Password")

Upvotes: 1

Views: 1476

Answers (4)

ragingloon
ragingloon

Reputation: 1

This is a password checker I made that checks for symbols and numbers as well as uppercase letters:

def check_password(password):
   strength = 0
   symbol_list = ['!','@','#','$','%','^','&','*','(',')','[',']','{','}',';',':','<','>',',','.']
   num_list =  ['1','2','3','4','5','6','7','8','9','0'] 
   if len(password) >= 8:
   # this is the part that checks for capitol letters
      for k in password:
         if k == k.upper:
            strength +=1
      for i in symbol_list:
         if i in password:
            strength+=1
      for j in num_list:
         if j in password:
            strength += 1
      # determines the strength
      if strength <= 5:
         print("Weak password")
      elif strength > 5 and strength < 8:
         print("Ok Password")
      if strength > 8:
         print("Strong password")
   else:
      print("Password too short")

Note: you can change the values in the if statements to suit your needs.

Upvotes: 0

ANVGJSENGRDG
ANVGJSENGRDG

Reputation: 153

Ok. The .upper() and .lower() method of figuring out if the string is all capital or all lowercase letters wont work if a number or special character is included in the string.

instead, use .isupper() to check if a specific character in a string is uppercase. and .islower() for lowercase. These methods each check character by character in the string, so the code line would be:

if any(x.isupper() for x in pw) and any(x.islower() for x in pw):

so the complete code (with organization of the logic) would be:

print("Password Checker")
pw=input("Enter Your Password Here: ")

#checking if password is to short, or to long.
if len(pw)<=5 or len(pw)>=13:
    if len(pw)<=5:
        print ("To Short")
    else:
        print ("Too Long")

else:#password is correct length
    #checking if a uppercase AND a lowwercase.
    if any(x.isupper() for x in pw) and any(x.islower() for x in pw):
        print ("Thats A STRONG Password")
    else:
        print ("Medium Password")

Let me know if I can answer any further questions about this.

NOTE: change from using input() to raw_input() to be compatible with python 2.7

Upvotes: 1

Nimander
Nimander

Reputation: 77

if pw==pw.upper() and pw==pw.lower():
    print("Thats A STRONG Password")

You're checking here if pw is uppercase and lowercase in the same time. I think you wanted to check if password is NOT only lowercase AND NOT only uppercase. So it should be

if pw != pw.upper() and pw != pw.lower():
    print("Thats A STRONG Password")

And of course in "Weak pass" it should be

if pw == pw.upper() or pw == pw.lower():
    print("Thats A WEAK Password")

because you're checking if pass is all lowercase OR all uppercase

Upvotes: 2

Cory Kramer
Cory Kramer

Reputation: 117856

Your logic is backwards here

if pw!=pw.upper() or pw!=pw.lower():

You'd use either

if pw != pw.upper() and pw != pw.lower():

or

if pw == pw.upper() or pw == pw.lower():

You have a similar problem at a later line

if pw==pw.upper() and pw==pw.lower():

If you want to check that there are at least one upper and one lower letter you can do something like

import string
if any(i in string.ascii_lowercase for i in pw) and any(i in string.ascii_uppercase for i in pw):

Upvotes: 2

Related Questions