/
SofiMut
/
passwordCheker
Обзор
Документация
Войти
/
SofiMut
/
passwordCheker
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
PasswordCheker.java
45 строк
1 KB
Софья Степанова
upload files
01 июл 2025, 07:42
01 июл 2025, 07:42
ee4f8c4
Код
Авторство
О чём код?
public class PasswordCheker { public int minLenght; public int maxRepeat; public void setMinLenght(int minLenght) throws RuntimeException { if (minLenght < 0) { String result = Integer.toString(minLenght); throw new PasswordIllegalArgumentException(result); } this.minLenght = minLenght; } public void setMaxRepeat(int maxRepeat) { if (maxRepeat < 1) { String result = Integer.toString(maxRepeat); throw new PasswordIllegalArgumentException(result); } this.maxRepeat = maxRepeat; } public boolean verify(String password) { if (minLenght == -1 || maxRepeat == -1) { throw new IllegalStateException("Данные для чеккера отсутствуют"); } if (password.length() < minLenght) { return false; } int counter = 0; char letter1 = password.charAt(0); for (char letter : password.toCharArray()) { if (letter == letter1) { counter++; } else { counter = 1; } if (counter > maxRepeat) { return false; } letter1 = letter; } return true; } }