/
Ersh
/
Stacktrace
Обзор
Документация
Войти
/
Ersh
/
Stacktrace
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
src/PasswordChecker.java
61 строка
2 KB
Ersh
upload files
13 авг 2025, 14:18
13 авг 2025, 14:18
25a4e90
Код
Авторство
О чём код?
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("Максимальное количество повторений должно быть больше 0"); } this.maxRepeats = maxRepeats; } // Проверка пароля public boolean verify(String password) { if (minLength == null || maxRepeats == null) { throw new IllegalStateException("Не все настройки чекера установлены: minLength или maxRepeats"); } if (password.length() < minLength) { return false; } if (hasTooManyRepeats(password, maxRepeats)) { return false; } return true; } private boolean hasTooManyRepeats(String password, int maxRepeats) { if (password.isEmpty()) return false; char prev = password.charAt(0); int count = 1; for (int i = 1; i < password.length(); i++) { char current = password.charAt(i); if (current == prev) { count++; if (count > maxRepeats) { return true; } } else { count = 1; prev = current; } } return false; } }