From 6d433ae67857625de956d9ec23bf2aba1e3664ea Mon Sep 17 00:00:00 2001 From: Vincent Richard Date: Thu, 26 Jan 2006 21:27:56 +0000 Subject: [PATCH] Non-SASL authenticator. --- examples/example6.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/examples/example6.cpp b/examples/example6.cpp index 6d8fe92f..344a4d87 100644 --- a/examples/example6.cpp +++ b/examples/example6.cpp @@ -35,7 +35,9 @@ static vmime::ref g_session = vmime::create (); -// Authentification handler +#if VMIME_HAVE_SASL_SUPPORT + +// SASL authentication handler class interactiveAuthenticator : public vmime::security::sasl::defaultSASLAuthenticator { const std::vector > getAcceptableMechanisms @@ -97,6 +99,46 @@ private: mutable vmime::string m_password; }; +#else // !VMIME_HAVE_SASL_SUPPORT + +// Simple authentication handler +class interactiveAuthenticator : public vmime::security::defaultAuthenticator +{ + const vmime::string getUsername() const + { + if (m_username.empty()) + m_username = getUserInput("Username"); + + return m_username; + } + + const vmime::string getPassword() const + { + if (m_password.empty()) + m_password = getUserInput("Password"); + + return m_password; + } + + static const vmime::string getUserInput(const std::string& prompt) + { + std::cout << prompt << ": "; + std::cout.flush(); + + vmime::string res; + std::getline(std::cin, res); + + return res; + } + +private: + + mutable vmime::string m_username; + mutable vmime::string m_password; +}; + +#endif // VMIME_HAVE_SASL_SUPPORT + #if VMIME_HAVE_TLS_SUPPORT