MCPcopy Create free account
hub / github.com/ddnet/ddnet / ConAuthUpdateHashed

Method ConAuthUpdateHashed

src/engine/server/server.cpp:3738–3782  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3736}
3737
3738void CServer::ConAuthUpdateHashed(IConsole::IResult *pResult, void *pUser)
3739{
3740 CServer *pThis = (CServer *)pUser;
3741 CAuthManager *pManager = &pThis->m_AuthManager;
3742
3743 const char *pIdent = pResult->GetString(0);
3744 const char *pLevel = pResult->GetString(1);
3745 const char *pPw = pResult->GetString(2);
3746 const char *pSalt = pResult->GetString(3);
3747
3748 int KeySlot = pManager->FindKey(pIdent);
3749 if(KeySlot == -1)
3750 {
3751 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "ident couldn't be found");
3752 return;
3753 }
3754
3755 int Level = GetAuthLevel(pLevel);
3756 if(Level == -1)
3757 {
3758 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "level can be one of {\"admin\", \"mod(erator)\", \"helper\"}");
3759 return;
3760 }
3761 // back compat to change "mod", "modder" and so on as parameters to "moderator"
3762 pLevel = CAuthManager::AuthLevelToRoleName(Level);
3763
3764 MD5_DIGEST Hash;
3765 unsigned char aSalt[SALT_BYTES];
3766
3767 if(md5_from_str(&Hash, pPw))
3768 {
3769 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "Malformed password hash");
3770 return;
3771 }
3772 if(str_hex_decode(aSalt, sizeof(aSalt), pSalt))
3773 {
3774 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "Malformed salt hash");
3775 return;
3776 }
3777
3778 pManager->UpdateKeyHash(KeySlot, Hash, aSalt, pLevel);
3779 pThis->LogoutKey(KeySlot, "key update");
3780
3781 pThis->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "auth", "key updated");
3782}
3783
3784void CServer::ConAuthRemove(IConsole::IResult *pResult, void *pUser)
3785{

Callers

nothing calls this directly

Calls 9

GetAuthLevelFunction · 0.85
md5_from_strFunction · 0.85
str_hex_decodeFunction · 0.85
FindKeyMethod · 0.80
UpdateKeyHashMethod · 0.80
LogoutKeyMethod · 0.80
GetStringMethod · 0.45
PrintMethod · 0.45
ConsoleMethod · 0.45

Tested by

no test coverage detected