~forsslundsystems/forssim/caseRevisionhandling

« back to all changes in this revision

Viewing changes to FsWisdom/ApplicationNode.cpp

  • Committer: Jocke Karlsson
  • Date: 2009-07-14 13:08:21 UTC
  • mfrom: (302.2.1 newhashOpenSSL)
  • Revision ID: jocke.karlsson@hiq.se-20090714130821-s2vzvo1bgm2o95kg
Merged from lp:~forsslundsystems/forssim/newhashOpenSSL Change to Open SSL standard lib MD5 hash.

Show diffs side-by-side

added added

removed removed

Lines of Context:
209
209
        selectCaseWindow->close();
210
210
}
211
211
 
212
 
int ApplicationNode::hashUsername(QString original)
 
212
QString ApplicationNode::hashUsername(QString original)
213
213
{
214
 
        string cr = original.toStdString();
215
 
        int b    = 378551; //Random Ranges I've chosen (can be modified)
216
 
        int a    = 63689;
217
 
        int hash = 0;  //Output hash
218
 
        int i;  //Temp number that scrolls through the string array
219
 
 
220
 
        for(i = 0; i < cr.length(); i++) //Loop to convert each character
221
 
        {
222
 
                hash = hash * a + cr[i];  //Algorithm that hashs
223
 
                a    = a * b;
224
 
        }
225
 
 
226
 
        return (hash & 0x7FFFFFFF); //Returns the hashed string
 
214
      string cr;
 
215
 
 
216
          cr = original.toStdString();
 
217
 
 
218
          unsigned char buf[MD5_DIGEST_LENGTH];
 
219
 
 
220
          MD5((unsigned char *)cr.c_str(), cr.length(), buf);
 
221
 
 
222
          std::ostringstream stm;
 
223
 
 
224
          for (int i=0;i<MD5_DIGEST_LENGTH;i++)
 
225
                  stm << hex << setfill('0') << setw(2) << nouppercase << (unsigned short)buf[i];
 
226
 
 
227
 
 
228
         return QString::fromStdString(stm.str());
227
229
}
228
230
 
 
231
 
 
232
 
229
233
void ApplicationNode::RegisterUser(QString username, QString password)
230
234
{
231
235
        this->setOverrideCursor(QCursor(Qt::WaitCursor));
234
238
        this->password = password;
235
239
 
236
240
        cout << "username: " << username.toStdString() << endl;
237
 
        int temp = hashUsername(username);
238
 
        QString hashUsername = QString::number(temp,10);
239
 
        hashUsername.insert(0,"u");
 
241
        QString temp = hashUsername(username+password);
 
242
        QString hashUsername = temp.left(16);
 
243
        QString hashPassword = temp.right(16);
 
244
 
240
245
        cout << "Hashed Username: " << hashUsername.toStdString() << endl;
 
246
        cout << "Hashed password: " << hashPassword.toStdString() << endl;
241
247
 
242
248
        /* Maybe need to connect to database and make a query instead. It could be other problems than
243
249
         * incorrect user name and password.
245
251
        forsDatabase.setHostName(databaseIP);
246
252
        forsDatabase.setDatabaseName(databaseName);
247
253
        forsDatabase.setUserName(hashUsername);
248
 
        forsDatabase.setPassword(password);
 
254
        forsDatabase.setPassword(hashPassword);
249
255
        if(!forsDatabase.open())
250
256
        {
251
257
                throw ApplicationNodeException("Please check username and password.");