-4

I had an assignment for school with a test to make a program that checks password strength. as you can see below i've made the program. When I turned it in, I received it back because it's to convenient to use the builtin function any(). how can i adjust or change my program to not include the any() function.

import time

print ("Check of uw wachtwoord veilig genoeg is in dit programma.")
time.sleep(1)
print ("Uw wachtwoord moet tussen minimaal 6 en maximaal 12 karakters
bestaan")
print ("U kunt gebruik maken van hoofdletters,getallen en symbolen (@,#,$,%)")


klein = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
groot = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
nummers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
symbolen= [' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]

def ok(passwd,l):
return any(k in passwd for k in l)  # checkt of een letter in de lijst in   het wachtwoord zit.

while True:
    inp = input("Wilt u dit programma gebruiken? ja/nee: ")
    if inp == "nee" and "Nee" and "NEE":
    break

elif inp == "ja" and "Ja" and "JA":
    ww = input("Voer uw wachtwoord in: ")
    if len(ww) < 6:
        print ("uw wachtwoord is te kort, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
    elif len(ww) > 12:
        print ("uw wachtwoord is te lang, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
    elif len(ww) >= 6 and len(ww)<= 12:
        sww = set(ww)           # set is een onorganiseerde verzameling dat betekent dat het niet op order is bijv. SaUj%2F3 = Oonorganiseerd        
        if all(ok(sww,l) for l in [klein,groot,nummers,symbolen]):
            print ("uw wachtwoord is Zeer sterk")
        elif all(ok(sww,l) for l in [klein,groot,nummers]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [klein,groot,symbolen]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [groot,nummers,symbolen]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [nummers,symbolen,klein]):
            print ("uw wachtwoord is Sterk")
        elif all(ok(sww,l) for l in [nummers,symbolen]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [groot,nummers]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [groot,symbolen]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein,groot]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein,nummers]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein,symbolen]):
            print ("uw wachtwoord is Medium")
        elif all(ok(sww,l) for l in [klein]):
            print ("uw wachtwoord is Zwak")
        elif all(ok(sww,l) for l in [symbolen]):
            print ("uw wachtwoord is Zwak")
        elif all(ok(sww,l) for l in [nummers]):
            print ("uw wachtwoord is Zwak")
        elif all(ok(sww,l) for l in [groot]):
            print ("uw wachtwoord is Zwak")
Christian Dean
  • 22,138
  • 7
  • 54
  • 87
  • 1
    I don't think it was returned because you used `any()`. Your code has errors. Try entering `NEE` for example. See https://stackoverflow.com/questions/15112125/how-do-i-test-one-variable-against-multiple-values to understand where you are going wrong there. – Martijn Pieters Sep 30 '16 at 09:35
  • 1
    Your indentation is also glaringly wrong; the code as posted won't run. – Martijn Pieters Sep 30 '16 at 09:36
  • This is a follow-on question from http://stackoverflow.com/questions/39756616/how-do-i-check-conditions-with-a-list-in-python-3 – PM 2Ring Sep 30 '16 at 10:17

1 Answers1

0

After fixing errors with the original

import time

print ("Check of uw wachtwoord veilig genoeg is in dit programma.")
time.sleep(1)
print ("Uw wachtwoord moet tussen minimaal 6 en maximaal 12 karakters bestaan")
print ("U kunt gebruik maken van hoofdletters,getallen en symbolen (@,#,$,%)")


klein = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
groot = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
nummers = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
symbolen= [' ', '!', '#', '$', '%', '&', '"', '(', ')', '*', '+', ',', '-', '.', '/', ':', ';', '<', '=', '>', '?', '@', '[', '\\', ']', '^', '_', '`', '{', '|', '}', '~',"'"]

def ok(passwd,l):
    return any(k in passwd for k in l)  # checkt of een letter in de lijst in   het wachtwoord zit.

while True:
    inp = raw_input("Wilt u dit programma gebruiken? ja/nee: ")
    if inp.lower() == "nee":
        break
    elif inp.lower() == "ja":
        ww = raw_input("Voer uw wachtwoord in: ")
        if len(ww) < 6:
            print ("uw wachtwoord is te kort, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
        elif len(ww) > 12:
            print ("uw wachtwoord is te lang, uw wachtwoord moet uit minimaal 6 en maximaal 12 karakters bestaan!")
        elif len(ww) >= 6 and len(ww)<= 12:
            sww = set(ww)           # set is een onorganiseerde verzameling dat betekent dat het niet op order is bijv. SaUj%2F3 = Oonorganiseerd        
            if all(ok(sww,l) for l in [klein,groot,nummers,symbolen]):
                print ("uw wachtwoord is Zeer sterk")
            elif all(ok(sww,l) for l in [klein,groot,nummers]):
                print ("uw wachtwoord is Sterk")
            elif all(ok(sww,l) for l in [klein,groot,symbolen]):
                print ("uw wachtwoord is Sterk")
            elif all(ok(sww,l) for l in [groot,nummers,symbolen]):
                print ("uw wachtwoord is Sterk")
            elif all(ok(sww,l) for l in [nummers,symbolen,klein]):
                print ("uw wachtwoord is Sterk")
            elif all(ok(sww,l) for l in [nummers,symbolen]):
                print ("uw wachtwoord is Medium")
            elif all(ok(sww,l) for l in [groot,nummers]):
                print ("uw wachtwoord is Medium")
            elif all(ok(sww,l) for l in [groot,symbolen]):
                print ("uw wachtwoord is Medium")
            elif all(ok(sww,l) for l in [klein,groot]):
                print ("uw wachtwoord is Medium")
            elif all(ok(sww,l) for l in [klein,nummers]):
                print ("uw wachtwoord is Medium")
            elif all(ok(sww,l) for l in [klein,symbolen]):
                print ("uw wachtwoord is Medium")
            elif all(ok(sww,l) for l in [klein]):
                print ("uw wachtwoord is Zwak")
            elif all(ok(sww,l) for l in [symbolen]):
                print ("uw wachtwoord is Zwak")
            elif all(ok(sww,l) for l in [nummers]):
                print ("uw wachtwoord is Zwak")
            elif all(ok(sww,l) for l in [groot]):
                print ("uw wachtwoord is Zwak")

if you really do not want to use any() something like the following would do

def ok(passwd,l):
    for c in passwd:
        if c in l: return True
    return False

iterates through the password until it finds a character within the list

Simon Black
  • 913
  • 8
  • 20