|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 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 PyQt4.QtCore import pyqtSlot |
|
11 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
12 |
|
13 from .Ui_MasterPasswordEntryDialog import Ui_MasterPasswordEntryDialog |
|
14 |
|
15 from Utilities.crypto.py3PBKDF2 import verifyPassword |
|
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 QDialog.__init__(self, 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.trUtf8("(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 enable = \ |
|
49 verifyPassword(self.currentPasswordEdit.text(), self.__oldPasswordHash) |
|
50 if not enable: |
|
51 error = error or self.trUtf8("Wrong password entered.") |
|
52 |
|
53 if self.newPasswordEdit.text() == "": |
|
54 enable = False |
|
55 error = error or self.trUtf8("New password must not be empty.") |
|
56 |
|
57 if self.newPasswordEdit.text() != "" and \ |
|
58 self.newPasswordEdit.text() != self.newPasswordAgainEdit.text(): |
|
59 enable = False |
|
60 error = error or self.trUtf8("Repeated password is wrong.") |
|
61 |
|
62 if self.currentPasswordEdit.isEnabled(): |
|
63 if self.newPasswordEdit.text() == self.currentPasswordEdit.text(): |
|
64 enable = False |
|
65 error = error or self.trUtf8("Old and new password must not be the same.") |
|
66 |
|
67 self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable) |
|
68 self.errorLabel.setText(error) |
|
69 |
|
70 @pyqtSlot(str) |
|
71 def on_currentPasswordEdit_textChanged(self, txt): |
|
72 """ |
|
73 Private slot to handle changes of the current password. |
|
74 |
|
75 @param txt content of the edit widget (string) |
|
76 """ |
|
77 self.__updateUI() |
|
78 |
|
79 @pyqtSlot(str) |
|
80 def on_newPasswordEdit_textChanged(self, txt): |
|
81 """ |
|
82 Private slot to handle changes of the new password. |
|
83 |
|
84 @param txt content of the edit widget (string) |
|
85 """ |
|
86 self.passwordMeter.checkPasswordStrength(txt) |
|
87 self.__updateUI() |
|
88 |
|
89 @pyqtSlot(str) |
|
90 def on_newPasswordAgainEdit_textChanged(self, txt): |
|
91 """ |
|
92 Private slot to handle changes of the new again password. |
|
93 |
|
94 @param txt content of the edit widget (string) |
|
95 """ |
|
96 self.__updateUI() |
|
97 |
|
98 def getMasterPassword(self): |
|
99 """ |
|
100 Public method to get the new master password. |
|
101 """ |
|
102 return self.newPasswordEdit.text() |
|
103 |
|
104 def getCurrentPassword(self): |
|
105 """ |
|
106 Public method to get the current master password. |
|
107 """ |
|
108 return self.currentPasswordEdit.text() |