/
Krygant
/
PasswordChecker
Обзор
Документация
Войти
/
Krygant
/
PasswordChecker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
PasswordChecker.java
45 строк
1 KB
Антон Крыгин
upload files
16 мар 2025, 11:45
16 мар 2025, 11:45
76b152a
Код
Авторство
О чём код?
public class PasswordChecker { private int minLength = -1; private int maxRepeats = -1; public void setMinLength(int minLength) { if (minLength < 0) { throw new IllegalArgumentException("Длина пароля не может быть отрицательной"); } this.minLength = minLength; } public void setMaxRepeats(int maxRepeats) { if (maxRepeats <= 0) { throw new IllegalArgumentException("Количество повторений должно быть положительным"); } this.maxRepeats = maxRepeats; } public boolean verify(String password) { if (minLength == -1 || maxRepeats == -1) { throw new IllegalStateException("Чекер не настроен"); } if (password.length() < minLength) { return false; } int counter = 0; char previousLetter = password.charAt(0); for (char letter : password.toCharArray()) { if (previousLetter == letter) { counter++; } else { counter = 1; } if (counter > maxRepeats) { return false; } previousLetter = letter; } return true; } }