Koha/koha-tmpl/intranet-tmpl/prog/en/includes/password_check.inc
Josef Moravec e24e7ad7f1 Bug 19908: Do not use .optional in password match validation function
Test plan:
0) Aplly only first patch
1) You will be able to submit a from on member-password.pl even if the
passwords don't match
2) Apply this patch -> you can't be able to submit the form if the
paswords don't match, but you'll be able to submit the form when
password fields are blank

Signed-off-by: Roch D'Amour <roch.damour@inlibro.com>
Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2018-03-19 12:23:13 -03:00

25 lines
1.3 KiB
PHP

[% USE Koha %]
[% BLOCK add_password_check %]
<script type="text/javascript">
var pwd_title = "";
var pattern_title = "";
var new_password_node_name = "[% new_password %]";
[% IF Koha.Preference('RequireStrongPassword') %]
pwd_title = _("Password must contain at least %s characters, including UPPERCASE, lowercase and numbers").format([% minPasswordLength %]);
pattern_regex = /(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{[% minPasswordLength %],}/;
[% ELSIF minPasswordLength %]
pwd_title = _("Password must contain at least %s characters").format([% minPasswordLength %]);
pattern_regex = /.{[% minPasswordLength %],}/;
[% END %]
jQuery.validator.addMethod("password_strong", function(value, element){
return this.optional(element) || value == '****' || pattern_regex.test(value);
}, pwd_title);
jQuery.validator.addMethod("password_no_spaces", function(value, element){
return ( this.optional(element) || !value.match(/^\s/) && !value.match(/\s$/) );
}, _("Password contains leading and/or trailing spaces"));
jQuery.validator.addMethod("password_match", function(value, element){
var new_password_node = $("input[name='" + new_password_node_name + "']:first");
return value == $(new_password_node).val();
}, _("Please enter the same password as above"));
</script>
[% END %]