PDA

View Full Version : Suggestions on Login Prompt



fnmblot
13th May 2009, 21:07
I was wondering if anyone could direct me to an example of a login prompt that has a check box to "Remember Login Info." I would like to just write to a hidden file in the user's home directory if that kind of helps.

Here is what my main.cpp looks like that calls the login prompt, or maybe I should do it in the logindialog.cpp:


#include <QtGui/QApplication>
#include <QDesktopWidget>
#include <QSqlError>
#include <QMessageBox>
#include <QSqlDatabase>

#include "entryform.h"
#include "mainwindow.h"
#include "logindialog.h"

int main(int argc, char *argv[])
{
QString strRejected = "";
QApplication a(argc, argv);
LoginDialog dlg;
dlg.setWindowTitle("Login");
QSqlDatabase db = QSqlDatabase::addDatabase("QMYSQL");
if( dlg.exec() == QDialog::Accepted ){
db.setHostName(dlg.loginDlgUi.serverLE->text());
db.setDatabaseName(dlg.loginDlgUi.databaseLE->text());
db.setUserName(dlg.loginDlgUi.usernameLE->text());
db.setPassword(dlg.loginDlgUi.passwordLE->text());
if ( db.open() ) {
MainWindow w;
QRect r = w.geometry();
r.moveTopLeft(QApplication::desktop()->availableGeometry().topLeft());
w.setGeometry(r);

w.resize(800, 650);
w.show();
return a.exec();
}
} else {
QMessageBox::information(0,"Login Canceled!","Login Canceled!");
return 1;
}
strRejected = QString("The Login was rejected because: %1").arg(db.lastError().text()).toLatin1();
QMessageBox::information(0,"Login Rejected!",strRejected);
return 2;
};


Thanks in advance

fnmblot

lni
13th May 2009, 21:22
This looks like login for a database administrator?

Did you try phpMyAdmin?

fnmblot
14th May 2009, 16:27
yes, but I am designing a database entry/view/purchasing system for cataloging Music Scores for my publishing company. I do not want to use phpMyAdmin.

lni
14th May 2009, 18:30
ok...

You can save the username/password in a binary format of your own choice so no one else knows the format, you also want the file to be protected so only the account owner has read permission...

On successful login, fire up your DB management window, otherwise, kick him out...

fnmblot
14th May 2009, 18:37
That is what I am thinking, but can you point me to an example on how to do this?

lni
15th May 2009, 00:40
That is what I am thinking, but can you point me to an example on how to do this?

There are a lot of examples that come with Qt source....

Check this website and see what its login screen look like: https://www.secform4.com/account/login

rbp
15th May 2009, 01:39
I remember my apps last login details with QSettings (http://doc.trolltech.com/4.5/qsettings.html#platform-specific-notes). On Linux this will store the data under the home directory and on Windows in the registry.
If you're concerned about security you could encrypt the login details before saving.

Richard

fnmblot
21st May 2009, 18:48
Thanks a million rbp. I used QSettings and it works wonderfully. I am just curious though, how could I encrypt the password using QSettings?

rbp
22nd May 2009, 02:08
I don't believe Qt has such a library. The closest one is the cryptographic library (http://doc.trolltech.com/4.5/qcryptographichash.html) for generating a hash of a string. Could you store your passwords as hashes?

If the user data is very sensitive you could investigate gnupg (http://gnupg.org) or cryptocpp (http://www.cryptopp.com/), but they seem over the top for your case.
Perhaps something simple like the Caesar cipher (http://en.wikipedia.org/wiki/Caesar_cipher) will do!

nietzsche
22nd May 2009, 19:54
Maybe this can help to you