eric6/Preferences/ConfigurationPages/MasterPasswordEntryDialog.py

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

eric ide

mercurial