/
merzlikina88
/
Stacktrace
Обзор
Документация
Войти
/
merzlikina88
/
Stacktrace
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordChecker.java
45 строк
1 KB
merzlikina88
upload files
13 дек 2025, 13:25
13 дек 2025, 13:25
232a514
Код
Авторство
О чём код?
public class PasswordChecker { private Integer minLength; private Integer maxRepeats; 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 == null || maxRepeats == null) { throw new IllegalStateException("Не все настройки заданы (minLength или maxRepeats)"); } if (password.length() < minLength) { return false; } for (int i = 0; i < password.length(); i++) { char currentChar = password.charAt(i); int repeatCount = 1; while (i + repeatCount < password.length() && password.charAt(i + repeatCount) == currentChar) { repeatCount++; } if (repeatCount > maxRepeats) { return false; } i += repeatCount - 1; } return true; } }