Skip to content

Instantly share code, notes, and snippets.

@royosherove
Created July 28, 2022 09:37
Show Gist options
  • Save royosherove/fb37068cd44bf55bda3aa2f4f9667454 to your computer and use it in GitHub Desktop.
Save royosherove/fb37068cd44bf55bda3aa2f4f9667454 to your computer and use it in GitHub Desktop.
Legacy Password Checker
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