havardt/PasswordValidator

[FEATURE REQUEST] keyboard character

FatuityCookie opened this issue · 1 comments

For example, is it a good idea to check the "qwer asdf ZxcV" character on the keyboard?

There is still a problem with people using bad passwords based on keyboard sequences like "qwerty", but it would probably be a better idea to just enforce basic checks like length and numbers that fix most problems. It's important to find a balance between forcing strong passwords and making it easy for the user to create a password.

Anyway, if you do want to check for keyboard sequences you could create a custom check and add it to the PasswordValidator like the following:

bool KeyboardSequenceCheck(string psw)
{
    List<string> keyboardSequences = new List<string>{"qwerty", "asdfghjk"};
    return ! keyboardSequences.Any(keyboardSequence => psw.Contains(keyboardSequence));
}

PasswordValidator validator = new PasswordValidator();
validator.AddCheck(nameof(KeyboardSequenceCheck), KeyboardSequenceCheck);