diff --git a/server/authoriz.cpp b/server/authoriz.cpp index 8ffb17145..2c80e6209 100755 --- a/server/authoriz.cpp +++ b/server/authoriz.cpp @@ -118,6 +118,8 @@ private: unsigned long m_Modules[3]; unsigned int m_nModules; wxString m_strLastPassword; + wxString m_strLastApp; + unsigned int m_nPwdCount; TUserTable m_Users; @@ -146,7 +148,7 @@ public: void ReturnInt(wxSocketBase& outs, unsigned int i); void ReturnBool(wxSocketBase&, bool b); - unsigned int DecodePassword(const wxChar* strPassword); + unsigned int DecodePassword(const wxChar* strPassword, const wxChar* strApp); void ProcessUserLogin(wxString cmd, wxSocketBase& sock); bool ProcessUserLogout(wxString cmd, wxSocketBase& sock); @@ -692,7 +694,7 @@ void TAuthorizationServer::ProcessFormCommand(wxString cmd, wxSocketBase& outs) } } -unsigned int TAuthorizationServer::DecodePassword(const wxChar* strPassword) +unsigned int TAuthorizationServer::DecodePassword(const wxChar* strPassword, const wxChar* strApp) { const unsigned int BASE = 19; unsigned int num = 0; @@ -716,13 +718,26 @@ unsigned int TAuthorizationServer::DecodePassword(const wxChar* strPassword) len++; } // Per essereva valido deve essere divisibile per 883 - if (len >= 5 && (num%883) == 0 && m_strLastPassword != strPassword) + if (len >= 5 && (num%883) == 0) { - // Creo la risposta: metà di num reso divisibile per 883 - num /= 2; - while (num % 883 != 0) - num++; - m_strLastPassword = strPassword; + if (m_strLastPassword != strPassword || m_strLastApp != strApp) + { + m_strLastPassword = strPassword; + m_strLastApp = strApp; + m_nPwdCount = 0; + } + else + m_nPwdCount++; + + if (m_nPwdCount < 8) + { + // Creo la risposta: metà di num reso divisibile per 883 + num /= 2; + while (num % 883 != 0) + num++; + } + else + num = 0; } else num = 0; @@ -748,19 +763,27 @@ void TAuthorizationServer::ProcessUserLogin(wxString cmd, wxSocketBase& sock) } else { - if (m_Users.Find(sock, strUser) == NULL && m_Users.GetCount() >= m_Dongle.MaxUsers()) + if (m_Users.GetCount() >= m_Dongle.MaxUsers() && m_Users.Find(sock, strUser) == NULL) + { + WriteLog("*** Maximum users exceeded"); num = 0; + } else { if (strcmp(strPassword, "******") == 0) // Older 16 bit version num = 1; else - num = DecodePassword(strPassword); + num = DecodePassword(strPassword, strProgram); if (num > 0) m_Users.AddConnection(sock, strUser); + else + WriteLog("*** Bad password"); } } } + else + WriteLog("*** Dongle not responding"); + ReturnInt(sock, num); }