/
Andreas_Serafishko
/
Project_A
Обзор
Документация
Войти
/
Andreas_Serafishko
/
Project_A
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
stacktrace/PasswordChecker.java
49 строк
2 KB
Andreas_Serafishko
upload files
07 авг 2025, 10:20
07 авг 2025, 10:20
1c3960b
Код
Авторство
О чём код?
package stacktrace; 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("PasswordChecker не настроен"); } if (password == null || password.length() < minLength) { return false; } int consecutiveCount = 1; // Считаем текущую последовательность подряд идущих символов char prevChar = password.charAt(0); for (int i = 1; i < password.length(); i++) { char currentChar = password.charAt(i); if (currentChar == prevChar) { consecutiveCount++; if (consecutiveCount > maxRepeats) { return false; // Слишком много повторений подряд } } else { consecutiveCount = 1; // Сброс счётчика при смене символа prevChar = currentChar; } } return true; } }