/
SamMih
/
HOMEWORK9_PasswordChecker
Обзор
Документация
Войти
/
SamMih
/
HOMEWORK9_PasswordChecker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordChecker.java
56 строк
2 KB
SamMih
HOMEWORK9_PasswordChecker
07 июл 2025, 13:55
07 июл 2025, 13:55
01dd6cf
Код
Авторство
О чём код?
public class PasswordChecker { protected int passwordLength; protected int repetitionOfSymbols; public PasswordChecker(int passwordLength, int repetitionOfSymbols) { this.passwordLength = passwordLength; this.repetitionOfSymbols = repetitionOfSymbols; } public void setPasswordLength(int passwordLength) { if (passwordLength < 0) { throw new IllegalArgumentException(passwordLength); } this.passwordLength = passwordLength; } public void setRepetitionOfSymbols(int repetitionOfSymbols) { if (repetitionOfSymbols <= 0) { throw new IllegalArgumentException(repetitionOfSymbols); } this.repetitionOfSymbols = repetitionOfSymbols; } public boolean verify(String password) { if (passwordLength == 0 || repetitionOfSymbols == 0) { throw new IllegalStateException(); } if (password.length() > passwordLength && MaxConsecutiveChar(password) < repetitionOfSymbols) { return true; } return false; } public static int MaxConsecutiveChar(String password) { if (password.isEmpty()) { return 0; } int maxCount = 1; int currentCount = 1; for (int i = 1; i < password.length(); i++) { if (password.charAt(i) == password.charAt(i-1)) { currentCount++; maxCount = Math.max(maxCount, currentCount); } else { currentCount = 1; } } return maxCount; } }