Koha/koha-tmpl/intranet-tmpl/prog/en/includes/password_check.inc
Jonathan Druart 7cc65af6ff Bug 18298: Use the validate jQuery plugin
To validate password fields we need to use the validate jQuery plugin.
To make things reusable this patch adds a new include file
'password_check.inc' at the intranet and opac sides, it creates 3 new
validation methods:
- password_strong => make sure the passwords are strong enough according
to the values of the RequireStrongPassword and minPasswordLength prefs
- password_no_spaces => prevent passwords to be entered with leading or
trailing spaces
- password_match => make sure both password fields match

Signed-off-by: Marc Véron <veron@veron.ch>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2017-10-16 09:44:32 -03:00

25 lines
1.4 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 this.optional(element) || value == $(new_password_node).val();
}, _("Please enter the same password as above"));
</script>
[% END %]