QTfrontend/net/newnetclient.cpp
changeset 10076 b235e520ea21
parent 10074 66cab76eb56f
child 10108 c68cf030eded
equal deleted inserted replaced
10075:dbaf90a0fbe0 10076:b235e520ea21
   237 }
   237 }
   238 
   238 
   239 void HWNewNet::SendPasswordHash(const QString & hash)
   239 void HWNewNet::SendPasswordHash(const QString & hash)
   240 {
   240 {
   241     // don't send it immediately, only store and check if server asked us for a password
   241     // don't send it immediately, only store and check if server asked us for a password
   242     m_passwordHash = hash;
   242     m_passwordHash = hash.toAscii();
   243 
   243 
   244     maybeSendPassword();
   244     maybeSendPassword();
   245 }
   245 }
   246 
   246 
   247 void HWNewNet::ParseCmd(const QStringList & lst)
   247 void HWNewNet::ParseCmd(const QStringList & lst)
   309         {
   309         {
   310             qWarning("Net: Malformed SERVER_AUTH message");
   310             qWarning("Net: Malformed SERVER_AUTH message");
   311             return;
   311             return;
   312         }
   312         }
   313 
   313 
   314         if(lst[2] != m_serverHash)
   314         if(lst[1] != m_serverHash)
   315         {
   315         {
   316             Error("Server authentication error");
   316             Error("Server authentication error");
   317             Disconnect();
   317             Disconnect();
   318         } else
   318         } else
   319         {
   319         {
  1143  */
  1143  */
  1144 
  1144 
  1145     if(m_passwordHash.isEmpty() || m_serverSalt.isEmpty())
  1145     if(m_passwordHash.isEmpty() || m_serverSalt.isEmpty())
  1146         return;
  1146         return;
  1147 
  1147 
  1148     QString hash;
  1148     QString hash = QCryptographicHash::hash(
  1149 
       
  1150     hash = QCryptographicHash::hash(
       
  1151                 m_clientSalt.toAscii()
  1149                 m_clientSalt.toAscii()
  1152                 .append(m_serverSalt.toAscii())
  1150                 .append(m_serverSalt.toAscii())
  1153                 .append(m_passwordHash)
  1151                 .append(m_passwordHash)
  1154                 .append(cProtoVer->toAscii())
  1152                 .append(cProtoVer->toAscii())
  1155                 .append("!hedgewars")
  1153                 .append("!hedgewars")
  1156                 , QCryptographicHash::Sha1);
  1154                 , QCryptographicHash::Sha1).toHex();
  1157 
  1155 
  1158     m_serverHash = QCryptographicHash::hash(
  1156     m_serverHash = QCryptographicHash::hash(
  1159                 m_serverSalt.toAscii()
  1157                 m_serverSalt.toAscii()
  1160                 .append(m_clientSalt.toAscii())
  1158                 .append(m_clientSalt.toAscii())
  1161                 .append(m_passwordHash)
  1159                 .append(m_passwordHash)
  1162                 .append(cProtoVer->toAscii())
  1160                 .append(cProtoVer->toAscii())
  1163                 .append("!hedgewars")
  1161                 .append("!hedgewars")
  1164                 , QCryptographicHash::Sha1);
  1162                 , QCryptographicHash::Sha1).toHex();
  1165 
  1163 
  1166     RawSendNet(QString("PASSWORD%1%2%1%3").arg(delimeter).arg(hash).arg(m_clientSalt));
  1164     RawSendNet(QString("PASSWORD%1%2%1%3").arg(delimeter).arg(hash).arg(m_clientSalt));
  1167 }
  1165 }