diff --git a/cps/admin.py b/cps/admin.py index 5667fcd3..85ea112f 100755 --- a/cps/admin.py +++ b/cps/admin.py @@ -1848,8 +1848,8 @@ def _handle_new_user(to_save, content, languages, translations, kobo_support): content.sidebar_view |= constants.DETAIL_RANDOM content.role = constants.selected_roles(to_save) - content.password = generate_password_hash(to_save["password"]) try: + content.password = generate_password_hash(helper.valid_password(to_save["password"])) if not to_save["name"] or not to_save["email"] or not to_save["password"]: log.info("Missing entries on new user") raise Exception(_(u"Please fill out all fields!")) @@ -1936,8 +1936,8 @@ def _handle_edit_user(to_save, content, languages, translations, kobo_support): log.warning("No admin user remaining, can't remove admin role from {}".format(content.name)) flash(_("No admin user remaining, can't remove admin role"), category="error") return redirect(url_for('admin.admin')) - if to_save.get("password"): - content.password = generate_password_hash(to_save["password"]) + if 'password' in to_save: + content.password = generate_password_hash(helper.valid_password(to_save('password'))) anonymous = content.is_anonymous content.role = constants.selected_roles(to_save) if anonymous: diff --git a/cps/helper.py b/cps/helper.py index d40ffc33..60bc1713 100755 --- a/cps/helper.py +++ b/cps/helper.py @@ -661,6 +661,23 @@ def valid_email(email): raise Exception(_(u"Invalid e-mail address format")) return email +def valid_password(check_password): + if config.config_password_policy: + verify = "" + if config.config_password_min_length > 0: + verify += "^(?=\S{" + str(config.config_password_min_length) + ",}$)" + if config.config_password_number: + verify += "(?=.*?\d)" + if config.config_password_lower: + verify += "(?=.*?[a-z])" + if config.config_password_upper: + verify += "(?=.*?[A-Z])" + if config.config_password_special: + verify += "(?=.*?[^A-Za-z\s0-9])" + match = re.match(verify, check_password) + if not match: + raise Exception(_("Password doesn't comply with password validation rules")) + return check_password # ################################# External interface ################################# diff --git a/cps/static/js/password.js b/cps/static/js/password.js index 209eea87..ecfe65fe 100644 --- a/cps/static/js/password.js +++ b/cps/static/js/password.js @@ -28,7 +28,8 @@ $(document).ready(function() { // Initialized and ready to go var options = {}; options.common = { - minChar: $('#password').data("min") + minChar: $('#password').data("min"), + maxChar: -1 } options.ui = { bootstrap3: true, diff --git a/cps/templates/config_edit.html b/cps/templates/config_edit.html index 22ce2de8..f6ccb5b3 100644 --- a/cps/templates/config_edit.html +++ b/cps/templates/config_edit.html @@ -389,7 +389,7 @@