eric6/E5Gui/E5PasswordMeter.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 custom widget indicating the strength of a password.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtWidgets import QProgressBar
13
14 from Utilities.PasswordChecker import PasswordChecker
15
16
17 class E5PasswordMeter(QProgressBar):
18 """
19 Class implementing a custom widget indicating the strength of a password.
20 """
21 def __init__(self, parent=None):
22 """
23 Constructor
24
25 @param parent reference to the parent widget (QWidget)
26 """
27 super(E5PasswordMeter, self).__init__(parent)
28
29 super(E5PasswordMeter, self).setTextVisible(False)
30 super(E5PasswordMeter, self).setMaximum(100)
31 self.__increment = 100 // (PasswordChecker.Complexity_VeryStrong + 1)
32
33 self.__indicatorColors = [
34 "#ff0000", # red
35 "#ff8800", # orange
36 "#ffff00", # yellow
37 "#ccff00", # yellow green
38 "#00ff00", # green
39 ]
40 self.__noIndicator = "#ffffff"
41
42 self.__styleSheetTemplate = \
43 "QProgressBar {{"\
44 " border: 2px solid black;" \
45 " border-radius: 5px;" \
46 " text-align: center; }}" \
47 "QProgressBar::chunk:horizontal {{" \
48 " background-color: {0}; }}"
49 self.setStyleSheet(
50 self.__styleSheetTemplate.format(self.__noIndicator))
51
52 def checkPasswordStrength(self, password):
53 """
54 Public slot to check the password strength and update the
55 progress bar accordingly.
56
57 @param password password to be checked (string)
58 """
59 strength = PasswordChecker().checkPassword(password)
60 self.setStyleSheet(self.__styleSheetTemplate.format(
61 self.__indicatorColors[strength]))
62 super(E5PasswordMeter, self).setValue(
63 (strength + 1) * self.__increment)
64
65 def setValue(self, value):
66 """
67 Public method to set the value.
68
69 Overwritten to do nothing.
70
71 @param value value (integer)
72 """
73 pass
74
75 def setMaximum(self, value):
76 """
77 Public method to set the maximum value.
78
79 Overwritten to do nothing.
80
81 @param value maximum value (integer)
82 """
83 pass
84
85 def setMinimum(self, value):
86 """
87 Public method to set the minimal value.
88
89 Overwritten to do nothing.
90
91 @param value minimum value (integer)
92 """
93 pass
94
95 if __name__ == "__main__":
96 import sys
97 from PyQt5.QtWidgets import QApplication
98
99 app = QApplication(sys.argv)
100 meter = E5PasswordMeter()
101 meter.show()
102 meter.checkPasswordStrength("Blah2+")
103 app.exec_()

eric ide

mercurial