Vasavi Balakrishnan
Vasavi Balakrishnan

Reputation: 19

python code to find out if a password contains sequences

For example a password may have the following sequences mentioned below. qwer,1234, 1qaz, qwe, qaz, qwer, asd, asdf,wsx, wsx, 2wsx,wer, asdf , 1234, zxcv, 5678 . qwer, 1234, qa , qwe, qaz.how do I write a simple python code to see if a password given to contains the above mention sequences

Upvotes: 1

Views: 257

Answers (1)

trevor
trevor

Reputation: 404

You can iterate through and test if the text is in the password. For example:

bad_strings = ["qwer", "1234", "1qaz", "qwe", "qaz", "qwer"]
passwords = ["blah347", "password1", "password2", "badqwer", "badqaz"]

def check_for_bad_password(password):
    for bad_string in bad_strings:
        if bad_string in password:
            return password

for password in passwords:
    if check_for_bad_password(password):
        print(password)

This prints out badqwer and badqaz

Upvotes: 0

Related Questions