summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/defaults.cpp3
-rw-r--r--src/gui/windows/logindialog.cpp12
-rw-r--r--src/net/ea/loginhandler.cpp18
-rw-r--r--src/progs/manaplus/client.cpp11
4 files changed, 37 insertions, 7 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 3ece72195..91c9e11b3 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -178,6 +178,9 @@ void setConfigDefaults(Configuration &cfg)
AddDEF("musicVolume", 60);
AddDEF("remember", false);
AddDEF("username", "");
+#ifdef SAVE_PASSWORD
+ AddDEF("password", "");
+#endif
AddDEF("lastCharacter", "");
AddDEF("altfpslimit", 5);
AddDEF("updatehost", "");
diff --git a/src/gui/windows/logindialog.cpp b/src/gui/windows/logindialog.cpp
index a8bb82c03..f169635dc 100644
--- a/src/gui/windows/logindialog.cpp
+++ b/src/gui/windows/logindialog.cpp
@@ -75,8 +75,12 @@ LoginDialog::LoginDialog(LoginData &data,
LoseFocusOnTab_true, nullptr, std::string(), false)),
mPassField(new PasswordField(this, mLoginData->password)),
// TRANSLATORS: login dialog label
+#ifdef SAVE_PASSWORD
+ mKeepCheck(new CheckBox(this, _("Remember user and password"),
+#else
mKeepCheck(new CheckBox(this, _("Remember username"),
- mLoginData->remember, nullptr, std::string())),
+#endif
+ mLoginData->remember, nullptr, std::string())),
// TRANSLATORS: login dialog label
mUpdateTypeLabel(new Label(this, _("Update:"))),
mUpdateTypeModel(new UpdateTypeModel),
@@ -202,8 +206,12 @@ void LoginDialog::postInit()
if (mUserField->getText().empty())
mUserField->requestFocus();
- else
+ else {
+#ifdef SAVE_PASSWORD
+ mPassField->setText(LoginDialog::savedPassword);
+#endif
mPassField->requestFocus();
+ }
mLoginButton->setEnabled(canSubmit());
if (loginHandler != nullptr)
diff --git a/src/net/ea/loginhandler.cpp b/src/net/ea/loginhandler.cpp
index 88b085aa3..92a2e9f35 100644
--- a/src/net/ea/loginhandler.cpp
+++ b/src/net/ea/loginhandler.cpp
@@ -151,15 +151,23 @@ void LoginHandler::loginOrRegister(LoginData *const data) const
else
loginAccount(data);
- // Clear the password, avoids auto login when returning to login
- data->password.clear();
-
const bool remember = data->remember;
- if (remember)
+ if (remember) {
serverConfig.setValue("username", data->username);
- else
+#ifdef SAVE_PASSWORD
+ serverConfig.setValue("password", data->password);
+#endif
+ }
+ else {
serverConfig.setValue("username", "");
+#ifdef SAVE_PASSWORD
+ serverConfig.setValue("password", "");
+#endif
+ }
serverConfig.setValue("remember", remember);
+
+ // Clear the password, avoids auto login when returning to login
+ data->password.clear();
}
void LoginHandler::logout() const
diff --git a/src/progs/manaplus/client.cpp b/src/progs/manaplus/client.cpp
index cea2d10af..d47404925 100644
--- a/src/progs/manaplus/client.cpp
+++ b/src/progs/manaplus/client.cpp
@@ -860,6 +860,11 @@ void Client::stateConnectServer1()
{
loginData.username = settings.options.username;
}
+#ifdef SAVE_PASSWORD
+ LoginDialog::savedPassword = loginData.remember ?
+ serverConfig.getValue("password", "") : "";
+ loginData.password = settings.options.password = LoginDialog::savedPassword;
+#endif
settings.login = loginData.username;
WindowManager::updateTitle();
@@ -1639,6 +1644,12 @@ int Client::gameExec()
case State::ERROR:
BLOCK_START("Client::gameExec State::ERROR")
config.write();
+#ifdef SAVE_PASSWORD
+ if(errorMessage == "Wrong password.") {
+ serverConfig.setValue("password", "");
+ serverConfig.write();
+ }
+#endif
if (mOldState == State::GAME)
serverConfig.write();
logger->log1("State: ERROR");