/
VladislavBasakevich
/
Stacktrace
Обзор
Документация
Войти
/
VladislavBasakevich
/
Stacktrace
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordChecker.java
47 строк
1 KB
VladislavBasakevich
upload files
07 апр 2025, 21:29
07 апр 2025, 21:29
bac462e
Код
Авторство
О чём код?
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("Количество повторений должно быть больше 0"); } 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 (letter == previousLetter){ counter++; } else { counter = 1; } if (counter > maxRepeats) { return false; } previousLetter = letter; } return true; } }