-1

I have been creating a program and I want it to check when a password is weak, medium or strong. I have defined each one of the uppercase, lowercase and digits so the program can check if the pass's strength. I have set it so a+b+c (all flags) is strong etc. but when I enter 7 characters, all lowercase it just restarts my program. I need it to tell me the password is weak etc. If anyone could give me any hints I would be grateful! Thanks!

import sys
import os
def checkPass():
    passLoop = True
    while passLoop:
        print("Welcome user!")
        x = len(input("Please enter your password, between 6 and 12 characters. "))#Asks for age
        if x <= 6 or x >= 12:
            print("Your password is the wrong length.")
            r = input("Please press any key to restart the program")
    passLoop = False
checkPass()
###########################
def upperCase(x):
    for char in x:
        if char.isupper():
            return(1)
        return(0)
###########################
def lowerCase(x):
    for char in x:
        if char.islower():
            return(1)
        return(0)
###########################
def digitFlag(x):
    for char in x:
        if char.isalnum():
            return(1)
        return(0)
###########################
def passStrength():
    a = upperCase
    b = lowerCase
    c = digitFlag
    totalValue =  a + b + c
    if totalValue == a or b or c:
        print("Your password is weak, please re-enter it!")
    if totalValue == a and b or a and c or b and c:
        print("Your password is medium, please re-enter it!")
    if totalValue == a and b and c:
        print("Your password is strong, please re-enter it!")
passStrength()
user3411623
  • 29
  • 1
  • 6
  • possible duplicate of [How do I test one variable against multiple values?](http://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values) – Cory Kramer Oct 16 '14 at 16:37
  • See the above link for why your if statements are incorrect e.g. `if totalValue == a or b or c:` – Cory Kramer Oct 16 '14 at 16:37
  • Don't use `0` and `1` as booleans; use `True` and `False`, and use `and` and `or` instead of arithmetics to check for multiple conditions. You could write your case-detection loops as one-liners: `any(c.islower() for c in the_password)`, etc. Also, I suppose your strength-detection algorithm is just an exercise; a real algorithm would also check password's entropy and check it against common dictionary words like `password` and `123`. – 9000 Oct 16 '14 at 16:42
  • Hi 9000. I have changed the 0 and 1 to True and False. This is only as practice. I now get the error TypeError: unsupported operand type(s) for +: 'function' and 'function' – user3411623 Oct 16 '14 at 17:35

2 Answers2

0

You didn't mention any stack trace or exceptions being thrown in your description, but I think that is what is happening to you. The problem is your use of input(). Change that to raw_input() and you should start to get the functionality you expect.

Have you ever heard of iPython? It is just a python shell environment, but it might be a utility that would have helped you more clearly see what was happening (noticing and even post-mortem debugging your application).

Let me know if that does not clear things up for you.

Guy Hoozdis
  • 111
  • 1
  • 6
0

Your problem is with that passLoop = False is never reached

Try this:

def checkPass():
    passLoop = True
    while passLoop:
        print("Welcome user!")
        x = len(input("Please enter your password, between 6 and 12 characters. "))#Asks for age
        if x <= 6 or x >= 12:
            print("Your password is the wrong length.")
            r = input("Please press any key to restart the program")
        else:
            passLoop = False
Svavelsyra
  • 140
  • 8
  • Hi. Thanks for replying so quickly! I have added what you suggested and it appears to create the error TypeError: unsupported operand type(s) for +: 'function' and 'function' on the line totalValue = a + b + c – user3411623 Oct 16 '14 at 16:59
  • Thats because a = upperCase dosn't call the function it just creates a reference to it. Try a = upperCase() and ofcourse similar for the other calls that miss it – Svavelsyra Oct 19 '14 at 10:47