/
haseew
/
Lab_6
Обзор
Документация
Войти
/
haseew
/
Lab_6
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Password.cpp
50 строк
2 KB
Egorchik
Lab_6
28 апр 2026, 17:44
28 апр 2026, 17:44
f0a1a80
Код
Авторство
О чём код?
#include "Password.h" #include <iostream> #include <cctype> // исправление регистра в имени конструктора базового исключения PasswordError::PasswordError(const std::string& msg) : std::runtime_error(msg) {} // исправление регистра для всех наследников ошибок LengthError::LengthError() : PasswordError("oshobka: dlinna parolja dolzhna byt ne menee 9 simvolov!") {} RegisterError::RegisterError() : PasswordError("oshibka: vse simvoly odnogo registra!") {} DigitError::DigitError() : PasswordError("oshibka: v parole net ni odnoj cifry!") {} ForbiddenLetterError::ForbiddenLetterError() : PasswordError("oshibka: najdeny zapreshchennye simvoly (l, I, 1, o, O, 0)!") {} std::string get_password() { std::string pwd; std::cout << "vvedite parol dlja proverki: "; std::cin >> pwd; // проверка длины пароля if (pwd.length() < 9) { throw LengthError(); } bool has_upper = false; bool has_lower = false; bool has_digit = false; for (char c : pwd) { if (std::isupper(c)) has_upper = true; if (std::islower(c)) has_lower = true; if (std::isdigit(c)) has_digit = true; // проверка путающих символов по заданию if (c == 'l' || c == 'I' || c == '1' || c == 'o' || c == 'O' || c == '0') { throw ForbiddenLetterError(); } } // проверка на одинаковый регистр всех букв if ((has_upper && !has_lower) || (has_lower && !has_upper) || (!has_upper && !has_lower)) { throw RegisterError(); } // проверка наличия хотя бы одной цифры if (!has_digit) { throw DigitError(); } return pwd; }