src/eric7/Preferences/ConfigurationPages/MasterPasswordEntryDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2011 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to enter or change the master password.
8 """
9
10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox
12
13 from .Ui_MasterPasswordEntryDialog import Ui_MasterPasswordEntryDialog
14
15
16 class MasterPasswordEntryDialog(QDialog, Ui_MasterPasswordEntryDialog):
17 """
18 Class implementing a dialog to enter or change the master password.
19 """
20 def __init__(self, oldPasswordHash, parent=None):
21 """
22 Constructor
23
24 @param oldPasswordHash hash of the current password (string)
25 @param parent reference to the parent widget (QWidget)
26 """
27 super().__init__(parent)
28 self.setupUi(self)
29
30 self.__oldPasswordHash = oldPasswordHash
31 if self.__oldPasswordHash == "":
32 self.currentPasswordEdit.setEnabled(False)
33 if hasattr(self.currentPasswordEdit, "setPlaceholderText"):
34 self.currentPasswordEdit.setPlaceholderText(
35 self.tr("(not defined yet)"))
36
37 self.buttonBox.button(
38 QDialogButtonBox.StandardButton.Ok).setEnabled(False)
39
40 def __updateUI(self):
41 """
42 Private slot to update the variable parts of the UI.
43 """
44 enable = True
45 error = ""
46 if self.currentPasswordEdit.isEnabled():
47 from Utilities.crypto.py3PBKDF2 import verifyPassword
48 enable = verifyPassword(
49 self.currentPasswordEdit.text(), self.__oldPasswordHash)
50 if not enable:
51 error = error or self.tr("Wrong password entered.")
52
53 if self.newPasswordEdit.text() == "":
54 enable = False
55 error = error or self.tr("New password must not be empty.")
56
57 if (
58 self.newPasswordEdit.text() != "" and
59 self.newPasswordEdit.text() != self.newPasswordAgainEdit.text()
60 ):
61 enable = False
62 error = error or self.tr("Repeated password is wrong.")
63
64 if (
65 self.currentPasswordEdit.isEnabled() and
66 self.newPasswordEdit.text() == self.currentPasswordEdit.text()
67 ):
68 enable = False
69 error = error or self.tr(
70 "Old and new password must not be the same.")
71
72 self.buttonBox.button(
73 QDialogButtonBox.StandardButton.Ok).setEnabled(enable)
74 self.errorLabel.setText(error)
75
76 @pyqtSlot(str)
77 def on_currentPasswordEdit_textChanged(self, txt):
78 """
79 Private slot to handle changes of the current password.
80
81 @param txt content of the edit widget (string)
82 """
83 self.__updateUI()
84
85 @pyqtSlot(str)
86 def on_newPasswordEdit_textChanged(self, txt):
87 """
88 Private slot to handle changes of the new password.
89
90 @param txt content of the edit widget (string)
91 """
92 self.passwordMeter.checkPasswordStrength(txt)
93 self.__updateUI()
94
95 @pyqtSlot(str)
96 def on_newPasswordAgainEdit_textChanged(self, txt):
97 """
98 Private slot to handle changes of the new again password.
99
100 @param txt content of the edit widget (string)
101 """
102 self.__updateUI()
103
104 def getMasterPassword(self):
105 """
106 Public method to get the new master password.
107
108 @return new master password (string)
109 """
110 return self.newPasswordEdit.text()
111
112 def getCurrentPassword(self):
113 """
114 Public method to get the current master password.
115
116 @return current master password (string)
117 """
118 return self.currentPasswordEdit.text()

eric ide

mercurial