diff options
author | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
---|---|---|
committer | Matthias Schiffer <matthias@gamezock.de> | 2009-09-27 19:58:24 +0200 |
commit | b40ba0cf91603b695f1f2380cbd39966a458f22f (patch) | |
tree | 1fec48ddc59eb1392fac38495b230e4b2cbf7528 /src/Client/Authenticators/PasswordAuthenticator.cpp | |
parent | e1d8490f0654a3da0b900407d80d91d8d0da68c8 (diff) | |
download | mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.tar mad-b40ba0cf91603b695f1f2380cbd39966a458f22f.zip |
Use Unicode-aware String class instead of std::string
Diffstat (limited to 'src/Client/Authenticators/PasswordAuthenticator.cpp')
-rw-r--r-- | src/Client/Authenticators/PasswordAuthenticator.cpp | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/src/Client/Authenticators/PasswordAuthenticator.cpp b/src/Client/Authenticators/PasswordAuthenticator.cpp index bf2a284..2ac9d68 100644 --- a/src/Client/Authenticators/PasswordAuthenticator.cpp +++ b/src/Client/Authenticators/PasswordAuthenticator.cpp @@ -35,17 +35,22 @@ void PasswordAuthenticator::PasswordAuthRequest::sendRequest() { packet.set("user", username); - if(hash == "Clear") - packet.set("data", std::vector<boost::uint8_t>(password.begin(), password.end())); - else - packet.set("data", Common::Hash::hash(std::vector<boost::uint8_t>(password.begin(), password.end()), hash)); + + + if(hash == "Clear") { + std::string passwordStr = password.extractUTF8(); + packet.set("data", std::vector<boost::uint8_t>(passwordStr.begin(), passwordStr.end())); + } + else { + packet.set("data", Common::Hash::hash(password, hash)); + } sendPacket(packet); } void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr<const Common::XmlData> packet) { if(packet->getType() == "Error") { - signalFinished(Core::Exception(packet->get<const std::string&>("Where"), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), + signalFinished(Core::Exception(packet->get<const Core::String&>("Where").extract(), static_cast<Core::Exception::ErrorCode>(packet->get<long>("ErrorCode")), packet->get<long>("SubCode"), packet->get<long>("SubSubCode"))); return; } @@ -57,8 +62,8 @@ void PasswordAuthenticator::PasswordAuthRequest::handlePacket(boost::shared_ptr< signalFinished(packet); } -void PasswordAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const std::string &username, const std::string &password) throw (Core::Exception) { - std::string hash; +void PasswordAuthenticator::authenticate(Common::Application *application, Common::Connection *con, const Core::String &username, const Core::String &password) throw (Core::Exception) { + Core::String hash; { boost::shared_ptr<Common::Requests::AuthMethodRequest> request(new Common::Requests::AuthMethodRequest(application)); @@ -74,14 +79,14 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo const Common::XmlData::List *methods = result.first->getList("methods"); for(Common::XmlData::List::const_iterator method = methods->begin(); method != methods->end(); ++method) { - if(method->get<const std::string&>("name") != "Password") + if(method->get<const Core::String&>("name") != "Password") continue; const Common::XmlData::List *subMethods = method->getList("subMethods"); for(Common::XmlData::List::const_iterator subMethod = subMethods->begin(); subMethod != subMethods->end(); ++subMethod) { - if(Common::Hash::isHashSupported(subMethod->get<const std::string&>("name"))) { - hash = subMethod->get<const std::string&>("name"); + if(Common::Hash::isHashSupported(subMethod->get<const Core::String&>("name"))) { + hash = subMethod->get<const Core::String&>("name"); break; } } @@ -89,11 +94,11 @@ void PasswordAuthenticator::authenticate(Common::Application *application, Commo break; } - if(hash.empty()) + if(hash.isEmpty()) throw Core::Exception(Core::Exception::NOT_AVAILABLE); } - application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.c_str()); + application->logf(Core::Logger::LOG_VERBOSE, "Authenticating with method 'Password' using hash '%s'...", hash.extract().c_str()); boost::shared_ptr<PasswordAuthRequest> request(new PasswordAuthRequest(application, username, password, hash)); |