Created
July 28, 2022 09:37
-
-
Save royosherove/fb37068cd44bf55bda3aa2f4f9667454 to your computer and use it in GitHub Desktop.
Legacy Password Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class PasswordVerifierLegacy() { | |
fun verify(password: String): Any { | |
var count = 1 | |
var messages:MutableList<String> = mutableListOf() | |
if (password.length < 8) messages.add("length less than 8") | |
if (password.firstOrNull { it.isDigit() } == null) messages.add("no digits") | |
if (password.firstOrNull { !it.isLetterOrDigit() } == null) messages.add("no regular characters") | |
if (password.filter { it.isLetter() }.firstOrNull { it.isUpperCase() } == null) messages.add("no uppercase") | |
if (password.filter { it.isLetter() }.firstOrNull { it.isLowerCase() } == null) messages.add("no lowercase") | |
return object { | |
val isValid = messages.count()<3 | |
val failedRulesCount = messages.count() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment