Шифрование является временным.
У меня совершенно нечитаемая ошибка во всех экземплярах функции execSqlAsync.
Ошибка:
In template: invalid operands to binary expression ('std::stringstream' (aka 'basic_stringstream') and 'std::exception') error occurred here in instantiation of function template specialization 'drogon::orm::Field::as' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::makeValue' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::run' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::run' requested here in instantiation of member function 'drogon::orm::internal::CallbackHolder::execCallback' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::CallbackHolder char {
if (c >= 'a' && c = 'A' && c getJsonObject();
std::string username = json->get("username", "").asString();
std::string password = json->get("password", "").asString();
// Encrypt the password using Caesar cipher
std::string encryptedPassword = caesarCipher(password, 3);
auto client = drogon::app().getDbClient().get();
client->execSqlAsync(
"INSERT INTO users (username, password_hash) VALUES ($1, $2)",
[callback](const Result &result) {
auto response = HttpResponse::newHttpResponse();
response->setStatusCode(HttpStatusCode::k200OK);
response->setBody("Signup successful");
callback(response);
},
[callback](const std::exception &e) { // Correct exception handling
auto response = HttpResponse::newHttpResponse();
response->setStatusCode(HttpStatusCode::k500InternalServerError);
response->setBody(e.what());
callback(response);
},
username, encryptedPassword);
}
void AuthController::login(const HttpRequestPtr &req, std::function &&callback) {
auto json = req->getJsonObject();
std::string username = json->get("username", "").asString();
std::string password = json->get("password", "").asString();
auto client = drogon::app().getDbClient();
client.get()->execSqlAsync(
"SELECT password_hash FROM users WHERE username = $1",
[password, callback](const Result &result) {
std::shared_ptr response;
if (!result.empty()) {
std::string storedHash = result[0]["password_hash"].as();
std::string decryptedPassword = caesarCipher(storedHash, -3);
if (decryptedPassword == password) {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k200OK);
response->setBody("Login successful");
} else {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k401Unauthorized);
response->setBody("Login failed");
}
} else {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k401Unauthorized);
response->setBody("User not found");
}
callback(response);
},
[callback](const std::exception &e) {
auto resp = HttpResponse::newHttpResponse();
resp->setStatusCode(k500InternalServerError);
resp->setBody(e.what());
callback(resp);
},
username);
}
Подробнее здесь: https://stackoverflow.com/questions/783 ... ism-drogon
Простой механизм аутентификации дрогон ⇐ C++
Программы на C++. Форум разработчиков
1713683146
Anonymous
Шифрование является временным.
У меня совершенно нечитаемая ошибка во всех экземплярах функции execSqlAsync.
Ошибка:
In template: invalid operands to binary expression ('std::stringstream' (aka 'basic_stringstream') and 'std::exception') error occurred here in instantiation of function template specialization 'drogon::orm::Field::as' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::makeValue' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::run' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::run' requested here in instantiation of member function 'drogon::orm::internal::CallbackHolder::execCallback' requested here in instantiation of function template specialization 'drogon::orm::internal::CallbackHolder::CallbackHolder char {
if (c >= 'a' && c = 'A' && c getJsonObject();
std::string username = json->get("username", "").asString();
std::string password = json->get("password", "").asString();
// Encrypt the password using Caesar cipher
std::string encryptedPassword = caesarCipher(password, 3);
auto client = drogon::app().getDbClient().get();
client->execSqlAsync(
"INSERT INTO users (username, password_hash) VALUES ($1, $2)",
[callback](const Result &result) {
auto response = HttpResponse::newHttpResponse();
response->setStatusCode(HttpStatusCode::k200OK);
response->setBody("Signup successful");
callback(response);
},
[callback](const std::exception &e) { // Correct exception handling
auto response = HttpResponse::newHttpResponse();
response->setStatusCode(HttpStatusCode::k500InternalServerError);
response->setBody(e.what());
callback(response);
},
username, encryptedPassword);
}
void AuthController::login(const HttpRequestPtr &req, std::function &&callback) {
auto json = req->getJsonObject();
std::string username = json->get("username", "").asString();
std::string password = json->get("password", "").asString();
auto client = drogon::app().getDbClient();
client.get()->execSqlAsync(
"SELECT password_hash FROM users WHERE username = $1",
[password, callback](const Result &result) {
std::shared_ptr response;
if (!result.empty()) {
std::string storedHash = result[0]["password_hash"].as();
std::string decryptedPassword = caesarCipher(storedHash, -3);
if (decryptedPassword == password) {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k200OK);
response->setBody("Login successful");
} else {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k401Unauthorized);
response->setBody("Login failed");
}
} else {
response = HttpResponse::newHttpResponse();
response->setStatusCode(k401Unauthorized);
response->setBody("User not found");
}
callback(response);
},
[callback](const std::exception &e) {
auto resp = HttpResponse::newHttpResponse();
resp->setStatusCode(k500InternalServerError);
resp->setBody(e.what());
callback(resp);
},
username);
}
Подробнее здесь: [url]https://stackoverflow.com/questions/78353393/a-simple-authentication-mechanism-drogon[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия