Merge pull request #769 from igniterealtime/save-password-from-preference-panel

SPARK-2320 Save password from Preferences menu
This commit is contained in:
ilyaHlevnoy 2022-12-18 18:15:24 +03:00 committed by GitHub
commit 6bd4ee9f3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -1395,7 +1395,7 @@ public class LoginUIPanel extends javax.swing.JPanel implements KeyListener, Act
// Check to see if the password should be saved or cleared from file.
if (savePasswordAfterSuccessfulLogin.get()) {
try {
localPref.setPasswordForUser(getLoginUsername() + "@" + getLoginServer(), getLoginPassword());
localPref.setPasswordForUser(getBareJid(), getLoginPassword());
} catch (Exception e) {
Log.error("Error storing encrypted password.", e);
}

View File

@ -29,6 +29,7 @@ import javax.swing.JTextField;
import org.jivesoftware.Spark;
import org.jivesoftware.resource.Default;
import org.jivesoftware.resource.Res;
import org.jivesoftware.spark.SparkManager;
import org.jivesoftware.spark.component.VerticalFlowLayout;
import org.jivesoftware.spark.util.ResourceUtils;
import org.jivesoftware.spark.util.log.Log;
@ -78,7 +79,16 @@ public class LocalPreferencePanel extends JPanel {
} else {
_savePasswordBox.addActionListener(e -> {
_autoLoginBox.setEnabled(_savePasswordBox.isSelected());
if (!_savePasswordBox.isSelected()) {
if (_savePasswordBox.isSelected()) {
String user = SparkManager.getSessionManager().getUserBareAddress().toString();
String password = SparkManager.getSessionManager().getPassword();
try {
preferences.setPasswordForUser(user,password);
} catch (Exception ex) {
Log.error("Error storing encrypted password.", ex);
}
}
if (!_savePasswordBox.isSelected()) {
_autoLoginBox.setSelected(false);
try {
preferences.clearPasswordForAllUsers();