简体   繁体   中英

Comparing a string with elements in a list

I'm trying to code a password strength checker, and I want to deduct points if the entered password is a common keyboard combination such as "qwerty" or "asdfg". I have a list that goes ['q', 'w', 'e', ... 'b', 'n', 'm'] . If any part of the input has consecutive elements from the list, I want to deduct points. Say the password is "djoDFGibTY" (Caps just to highlight, all lower case), I want my code to catch the "DFG" and "TY" and deduct points twice, with more points deducted in the first case for a triple violation and lesser in the second case for a double violation. Thank You.

keyboard_pattern = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm']

if password in keyboard_pattern:

score -= 15

As found on https://codereview.stackexchange.com/questions/177415/python-qwerty-keyboard-checker

input = input("What is your password?")
qwerty = 'qwertyuiopasdfghjklzxcvbnm'
lower = input.lower()
for idx in range(0, len(lower) - 2):
    test_seq = lower[idx:idx + 3]
    if test_seq in qwerty:
        points -= 5
print(points)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM