AntimoniumHeptadiene
AntimoniumHeptadiene

Reputation: 35

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

Upvotes: 2

Views: 61

Answers (1)

Jkind9
Jkind9

Reputation: 740

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)

Upvotes: 2

Related Questions