giusepped
28th September 2011, 16:10
Maybe I lost my intelligence, but I really do not why this code do not behave correctly.
bool loginDialog::check()
{
qDebug()<<"LD check"<<usernames<<passwords;
qDebug()<<"LD input"<<username<<password<<usernames.contains(username.trimmed());
QString p;
QByteArray in;
if (usernames.contains(username.trimmed()))
{
p = passwords.at(usernames.indexOf(username));
qDebug()<<"LD password"
"input"<<p<<QCryptographicHash::hash(password.toLocal8Bit(),QC ryptographicHash::Md5);
in = QCryptographicHash::hash(password.toLocal8Bit(),QC ryptographicHash::Md5);
if ( in == p)
{
qDebug()<<"ACCEPTED"<< p.toLocal8Bit() << in;
return true;
}
else
{
qDebug()<<"NO ACCEPTED"<<in<<p;
return false;
SleeperThread::msleep(900);
}
}
return false;
}
The output at run is as follow
LD check ("administrator") ("!#/)zW¥§C?JJ?Ã")
LD input "administrator" "admin" true
LD passwordinput "!#/)zW¥§C?JJ?Ã" "!#/)zW¥§C?JJ?Ã"
NO ACCEPTED "!#/)zW¥§C?JJ?Ã" "!#/)zW¥§C?JJ?Ã"
As you can see the variables "in" and "p" have the same value, but the "if" lands always in the NO ACCEPTED state.
Regards
bool loginDialog::check()
{
qDebug()<<"LD check"<<usernames<<passwords;
qDebug()<<"LD input"<<username<<password<<usernames.contains(username.trimmed());
QString p;
QByteArray in;
if (usernames.contains(username.trimmed()))
{
p = passwords.at(usernames.indexOf(username));
qDebug()<<"LD password"
"input"<<p<<QCryptographicHash::hash(password.toLocal8Bit(),QC ryptographicHash::Md5);
in = QCryptographicHash::hash(password.toLocal8Bit(),QC ryptographicHash::Md5);
if ( in == p)
{
qDebug()<<"ACCEPTED"<< p.toLocal8Bit() << in;
return true;
}
else
{
qDebug()<<"NO ACCEPTED"<<in<<p;
return false;
SleeperThread::msleep(900);
}
}
return false;
}
The output at run is as follow
LD check ("administrator") ("!#/)zW¥§C?JJ?Ã")
LD input "administrator" "admin" true
LD passwordinput "!#/)zW¥§C?JJ?Ã" "!#/)zW¥§C?JJ?Ã"
NO ACCEPTED "!#/)zW¥§C?JJ?Ã" "!#/)zW¥§C?JJ?Ã"
As you can see the variables "in" and "p" have the same value, but the "if" lands always in the NO ACCEPTED state.
Regards