mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-10-13 15:34:37 +00:00
Limit possibility of brute force attacks when guessing password
As suggested by elexis, 1a8de6d2b8 should get some protection against
brute force attacks on password.
This is supposed to prevent attackers from getting connection data by
guessing the password.
Each failed attempt increases the counter.
XmppClient on the server side checks for the users with certain number
of failed attempts, determined in CNetServer, and refuses to check the
password, answering with banned message.
So they cant guess again in given match. Effect of this block will
dissapear after new match is created.
Differential revision: D3467
Comments by: wraitii, Stan
Tested by: Stan, Freagarach
Ref: #5913
This was SVN commit r24794.
This commit is contained in:
@@ -58,6 +58,7 @@
|
||||
#define DEFAULT_SERVER_NAME L"Unnamed Server"
|
||||
|
||||
constexpr int CHANNEL_COUNT = 1;
|
||||
constexpr int FAILED_PASSWORD_TRIES_BEFORE_BAN = 3;
|
||||
|
||||
/**
|
||||
* enet_host_service timeout (msecs).
|
||||
@@ -1629,9 +1630,26 @@ void CNetServer::SetConnectionData(const CStr& ip, const u16 port, bool useSTUN)
|
||||
m_UseSTUN = useSTUN;
|
||||
}
|
||||
|
||||
bool CNetServer::CheckPassword(const CStr& password) const
|
||||
bool CNetServer::CheckPasswordAndIncrement(const CStr& password, const std::string& username)
|
||||
{
|
||||
return m_Password == password;
|
||||
std::unordered_map<std::string, int>::iterator it = m_FailedAttempts.find(username);
|
||||
if (m_Password == password)
|
||||
{
|
||||
if (it != m_FailedAttempts.end())
|
||||
it->second = 0;
|
||||
return true;
|
||||
}
|
||||
if (it == m_FailedAttempts.end())
|
||||
m_FailedAttempts.emplace(username, 1);
|
||||
else
|
||||
it->second++;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CNetServer::IsBanned(const std::string& username) const
|
||||
{
|
||||
std::unordered_map<std::string, int>::const_iterator it = m_FailedAttempts.find(username);
|
||||
return it != m_FailedAttempts.end() && it->second >= FAILED_PASSWORD_TRIES_BEFORE_BAN;
|
||||
}
|
||||
|
||||
void CNetServer::SetPassword(const CStr& password)
|
||||
|
||||
Reference in New Issue
Block a user