From d6ae2ea0948a4058d98a1bc80965a68d3abf5253 Mon Sep 17 00:00:00 2001 From: azhar3339 Date: Sun, 14 Sep 2014 00:23:36 +0400 Subject: [PATCH 1/3] Update password_dialog.py --- gui/qt/password_dialog.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gui/qt/password_dialog.py b/gui/qt/password_dialog.py index 1c2d1318..f6bf2693 100644 --- a/gui/qt/password_dialog.py +++ b/gui/qt/password_dialog.py @@ -84,6 +84,12 @@ def run_password_dialog(self, wallet, parent): new_password = unicode(self.new_pw.text()) new_password2 = unicode(self.conf_pw.text()) + #Check the length + if len(new_password) < 6 : + QMessageBox.warning(parent, _('Error'), _('Password id too short'), _('OK')) + # Retry + return run_password_dialog(self, wallet, parent) + if new_password != new_password2: QMessageBox.warning(parent, _('Error'), _('Passwords do not match'), _('OK')) # Retry From d12bd4fffdd026db2f8457c653072234dca1ad48 Mon Sep 17 00:00:00 2001 From: azhar3339 Date: Sun, 14 Sep 2014 13:22:59 +0400 Subject: [PATCH 2/3] Update password_dialog.py Added a restriction on password. It should be at least 6 characters, contain an Upper case letter and a special character. --- gui/qt/password_dialog.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/gui/qt/password_dialog.py b/gui/qt/password_dialog.py index f6bf2693..ed87e76c 100644 --- a/gui/qt/password_dialog.py +++ b/gui/qt/password_dialog.py @@ -20,6 +20,7 @@ from PyQt4.QtGui import * from PyQt4.QtCore import * from electrum.i18n import _ from util import * +import re @@ -60,7 +61,9 @@ def make_password_dialog(self, wallet, msg, new_pass=True): grid.addWidget(self.pw, 0, 1) grid.addWidget(QLabel(_('New Password') if new_pass else _('Password')), 1, 0) + self.password_help = HelpButton(_('Password must be at least 6 characters') + '\n\n' + _('It should contain a number, an uppercase alphabet and a special character')) grid.addWidget(self.new_pw, 1, 1) + grid.addWidget(self.password_help,1,4) grid.addWidget(QLabel(_('Confirm Password')), 2, 0) grid.addWidget(self.conf_pw, 2, 1) @@ -84,12 +87,6 @@ def run_password_dialog(self, wallet, parent): new_password = unicode(self.new_pw.text()) new_password2 = unicode(self.conf_pw.text()) - #Check the length - if len(new_password) < 6 : - QMessageBox.warning(parent, _('Error'), _('Password id too short'), _('OK')) - # Retry - return run_password_dialog(self, wallet, parent) - if new_password != new_password2: QMessageBox.warning(parent, _('Error'), _('Passwords do not match'), _('OK')) # Retry @@ -97,6 +94,26 @@ def run_password_dialog(self, wallet, parent): if not new_password: new_password = None + else: + #Check for password strength if user chooses to enter a password + #Check the length + if len(new_password) < 6 : + QMessageBox.warning(parent, _('Error'), _('Password is too short. It must be at least 6 characters') + '\n\n' + _('Click help beside the password button for more information'), _('OK')) + # Retry + return run_password_dialog(self, wallet, parent) + #Check for uppercase characters + if new_password.islower() or new_password.isnumeric(): + QMessageBox.warning(parent, _('Error'), _('Password must contain at least one Upper case alphabet') + '\n\n' + _('Click help beside the password button for more information'), _('OK')) + # Retry + return run_password_dialog(self, wallet, parent) + #Check for special characters + if (re.match('^[a-zA-Z0-9]*$',new_password)): + QMessageBox.warning(parent, _('Error'), _('Password must contain at least one special character') + '\n\n' + _('Click help beside the password button for more information'), _('OK')) + # Retry + return run_password_dialog(self, wallet, parent) + + + return True, password, new_password From 489152ff5a4508f28f73a0d48595aa9142e8603c Mon Sep 17 00:00:00 2001 From: azhar3339 Date: Tue, 16 Sep 2014 04:44:19 +0400 Subject: [PATCH 3/3] Update password_dialog.py Added a label that shows the password strength interactively as the user types the password. --- gui/qt/password_dialog.py | 76 +++++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 22 deletions(-) diff --git a/gui/qt/password_dialog.py b/gui/qt/password_dialog.py index ed87e76c..97e24ae4 100644 --- a/gui/qt/password_dialog.py +++ b/gui/qt/password_dialog.py @@ -32,6 +32,8 @@ def make_password_dialog(self, wallet, msg, new_pass=True): self.new_pw.setEchoMode(2) self.conf_pw = QLineEdit() self.conf_pw.setEchoMode(2) + #Password Strength Label + self.pw_strength = QLabel("Password Strength: Empty ") vbox = QVBoxLayout() label = QLabel(msg) @@ -61,14 +63,18 @@ def make_password_dialog(self, wallet, msg, new_pass=True): grid.addWidget(self.pw, 0, 1) grid.addWidget(QLabel(_('New Password') if new_pass else _('Password')), 1, 0) - self.password_help = HelpButton(_('Password must be at least 6 characters') + '\n\n' + _('It should contain a number, an uppercase alphabet and a special character')) grid.addWidget(self.new_pw, 1, 1) - grid.addWidget(self.password_help,1,4) + + #add Password Strength Label to grid + grid.addWidget(self.pw_strength, 1, 2) grid.addWidget(QLabel(_('Confirm Password')), 2, 0) grid.addWidget(self.conf_pw, 2, 1) vbox.addLayout(grid) + #Add an event handler to update password strength interactively + self.connect(self.new_pw, SIGNAL("textChanged(QString)"), lambda: update_password_strength(self.pw_strength,self.new_pw.text())) + vbox.addStretch(1) vbox.addLayout(ok_cancel_buttons(self)) return vbox @@ -94,29 +100,55 @@ def run_password_dialog(self, wallet, parent): if not new_password: new_password = None - else: - #Check for password strength if user chooses to enter a password - #Check the length - if len(new_password) < 6 : - QMessageBox.warning(parent, _('Error'), _('Password is too short. It must be at least 6 characters') + '\n\n' + _('Click help beside the password button for more information'), _('OK')) - # Retry - return run_password_dialog(self, wallet, parent) - #Check for uppercase characters - if new_password.islower() or new_password.isnumeric(): - QMessageBox.warning(parent, _('Error'), _('Password must contain at least one Upper case alphabet') + '\n\n' + _('Click help beside the password button for more information'), _('OK')) - # Retry - return run_password_dialog(self, wallet, parent) - #Check for special characters - if (re.match('^[a-zA-Z0-9]*$',new_password)): - QMessageBox.warning(parent, _('Error'), _('Password must contain at least one special character') + '\n\n' + _('Click help beside the password button for more information'), _('OK')) - # Retry - return run_password_dialog(self, wallet, parent) - - - return True, password, new_password +def check_password_strength(password): + + ''' + Check the strength of the password entered by the user and return back the same + :param password: password entered by user in New Password + :return: password strength Weak or Medium or Strong + ''' + + password_strength = {-1:"Empty",0:"Too short",1:"Weak",2:"Medium",3:"Medium",4:"Strong",5:"Strong"} + score = -1 + + if len(password) == 0: + return password_strength[score] + elif len(password) < 6: + score = score + 1 + return password_strength[score] + else: + score += 1 + + if re.search(r'[A-Z]', password): + score += 1 + + if re.search(r'[a-z]', password): + score += 1 + + if re.search(r'[0-9]', password): + score += 1 + + if not re.match("^[a-zA-Z0-9]*$",password): + score += 1 + + return password_strength[score] + +def update_password_strength(pw_strength_label,password): + + ''' + call the function check_password_strength and update the label pw_strength interactively as the user is typing the password + :param pw_strength_label: the label pw_strength + :param password: password entered in New Password text box + :return: None + ''' + colors = {"Empty":"Red","Too short":"Red","Weak":"Red","Medium":"Blue","Strong":"Green"} + strength = check_password_strength(password) + pw_strength_label.setText("Password Strength:" + strength + "") + + class PasswordDialog(QDialog):