/
msigin77
/
Home_work10
Обзор
Документация
Войти
/
msigin77
/
Home_work10
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordChecker.java
46 строк
2 KB
msigin77
д\10
17 дек 2025, 09:06
17 дек 2025, 09:06
36b5a59
Код
Авторство
О чём код?
public class PasswordChecker { private int minLength; private int 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 == 0 || maxRepeats == 0) { throw new IllegalStateException("Не заданы все настройки чекера. Установите minLength и maxRepeats."); } if (password.length() < minLength) { return false; } if (password.length() > 0) { char currentChar = password.charAt(0); int currentCount = 1; for (int i = 1; i < password.length(); i++) { if (password.charAt(i) == currentChar) { currentCount++; if (currentCount > maxRepeats) { return false; } } else { currentChar = password.charAt(i); currentCount = 1; } } } return true; } }