From 5e479f2f9022c173efd5121143e1474f0453154f Mon Sep 17 00:00:00 2001 From: Mark Watkins Date: Mon, 7 May 2018 08:10:17 +1000 Subject: [PATCH] Check password on login --- sleepyhead/newprofile.cpp | 2 ++ sleepyhead/profileselector.cpp | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/sleepyhead/newprofile.cpp b/sleepyhead/newprofile.cpp index b6025b5d..1d5a9d73 100644 --- a/sleepyhead/newprofile.cpp +++ b/sleepyhead/newprofile.cpp @@ -264,6 +264,8 @@ void NewProfile::on_nextButton_clicked() //profile->user->setUserName(username); AppSetting->setProfileName(username); + profile->Save(); + this->accept(); } } diff --git a/sleepyhead/profileselector.cpp b/sleepyhead/profileselector.cpp index d3c423b2..6f24befe 100644 --- a/sleepyhead/profileselector.cpp +++ b/sleepyhead/profileselector.cpp @@ -221,6 +221,41 @@ void ProfileSelector::SelectProfile(QString profname) Profile * prof = Profiles::profiles[profname]; if (prof != p_profile) { + if (prof->user->hasPassword()) { + QDialog dialog(this, Qt::Dialog); + QLineEdit *e = new QLineEdit(&dialog); + e->setEchoMode(QLineEdit::Password); + dialog.connect(e, SIGNAL(returnPressed()), &dialog, SLOT(accept())); + dialog.setWindowTitle(tr("Enter Password for %1").arg(profname)); + dialog.setMinimumWidth(300); + QVBoxLayout *lay = new QVBoxLayout(); + dialog.setLayout(lay); + lay->addWidget(e); + int tries = 0; + bool succeeded = false; + + do { + e->setText(""); + + if (dialog.exec() != QDialog::Accepted) { break; } + + tries++; + + if (prof->user->checkPassword(e->text())) { + succeeded = true; + break; + } else { + if (tries < 3) { + QMessageBox::warning(this, STR_MessageBox_Error, tr("You entered an incorrect password"), QMessageBox::Ok); + } else { + QMessageBox::warning(this, STR_MessageBox_Error, + tr("Forgot your password?")+"\n"+tr("Ask on the forums how to reset it, it's actually pretty easy."), + QMessageBox::Ok); + } + } + } while (tries < 3); + if (!succeeded) return; + } // Unselect everything in ProfileView