diff options
author | Tomás Touceda <chiiph@leap.se> | 2014-05-21 19:17:09 -0300 |
---|---|---|
committer | Tomás Touceda <chiiph@leap.se> | 2014-05-21 19:17:09 -0300 |
commit | e7cff9866e50f9730f8fc6ab70cf116ed38f7935 (patch) | |
tree | 1fd1c072a004719bc101e74e63e7c8c7219cd1c2 /src/leap/bitmask/util | |
parent | 2ba353fbc87eb81dde2f169b8facdb2104107f70 (diff) | |
parent | d0a9ecf0cba998b44a216c5cdf1800eea152f379 (diff) |
Merge remote-tracking branch 'refs/remotes/ivan/feature/fix-username-regex-support' into develop
Diffstat (limited to 'src/leap/bitmask/util')
-rw-r--r-- | src/leap/bitmask/util/credentials.py (renamed from src/leap/bitmask/util/password.py) | 31 |
1 files changed, 27 insertions, 4 deletions
diff --git a/src/leap/bitmask/util/password.py b/src/leap/bitmask/util/credentials.py index 73659f0d..a661bfb0 100644 --- a/src/leap/bitmask/util/password.py +++ b/src/leap/bitmask/util/credentials.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# password.py +# credentials.py # Copyright (C) 2013 LEAP # # This program is free software: you can redistribute it and/or modify @@ -16,14 +16,34 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. """ -Password utilities +Credentials utilities """ -from PySide import QtCore +from PySide import QtCore, QtGui WEAK_PASSWORDS = ("123456", "qweasd", "qwerty", "password") +USERNAME_REGEX = r"^[A-Za-z][A-Za-z\d_\-\.]+[A-Za-z]$" +USERNAME_VALIDATOR = QtGui.QRegExpValidator(QtCore.QRegExp(USERNAME_REGEX)) -def basic_password_checks(username, password, password2): + +def username_checks(username): + # translation helper + _tr = QtCore.QObject().tr + + message = None + + if message is None and len(username) < 2: + message = _tr("Username must have at least 2 characters") + + valid = USERNAME_VALIDATOR.validate(username, 0) + valid_username = valid[0] == QtGui.QValidator.State.Acceptable + if message is None and not valid_username: + message = _tr("Invalid username") + + return message is None, message + + +def password_checks(username, password, password2): """ Performs basic password checks to avoid really easy passwords. @@ -46,6 +66,9 @@ def basic_password_checks(username, password, password2): if message is None and password != password2: message = _tr("Passwords don't match") + if message is None and not password: + message = _tr("You can't use an empty password") + if message is None and len(password) < 6: message = _tr("Password too short") |