From: rojanu Date: Fri, 7 Jan 2011 14:14:40 +0000 (+0100) Subject: Bug 558803: Add a parameter to specify the password complexity for new passwords X-Git-Tag: bugzilla-4.1.1~103 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=02e52f810b396c5f367dc18b162d6a6724cab754;p=thirdparty%2Fbugzilla.git Bug 558803: Add a parameter to specify the password complexity for new passwords r/a=LpSolit --- diff --git a/Bugzilla/Config/Auth.pm b/Bugzilla/Config/Auth.pm index c7d921ed57..a61cab5a2e 100644 --- a/Bugzilla/Config/Auth.pm +++ b/Bugzilla/Config/Auth.pm @@ -121,6 +121,15 @@ sub get_param_list { type => 't', default => q:.*:, checker => \&check_regexp + }, + + { + name => 'password_complexity', + type => 's', + choices => [ 'no_constraints', 'mixed_letters', 'letters_numbers', + 'letters_numbers_specialchars' ], + default => 'no_constraints', + checker => \&check_multi } ); return @param_list; } diff --git a/Bugzilla/User.pm b/Bugzilla/User.pm index d151139591..eafda6563b 100644 --- a/Bugzilla/User.pm +++ b/Bugzilla/User.pm @@ -1946,6 +1946,19 @@ sub validate_password { } elsif ((defined $matchpassword) && ($password ne $matchpassword)) { ThrowUserError('passwords_dont_match'); } + + my $complexity_level = Bugzilla->params->{password_complexity}; + if ($complexity_level eq 'letters_numbers_specialchars') { + ThrowUserError('password_not_complex') + if ($password !~ /\w/ || $password !~ /\d/ || $password !~ /[[:punct:]]/); + } elsif ($complexity_level eq 'letters_numbers') { + ThrowUserError('password_not_complex') + if ($password !~ /[[:lower:]]/ || $password !~ /[[:upper:]]/ || $password !~ /\d/); + } elsif ($complexity_level eq 'mixed_letters') { + ThrowUserError('password_not_complex') + if ($password !~ /[[:lower:]]/ || $password !~ /[[:upper:]]/); + } + # Having done these checks makes us consider the password untainted. trick_taint($_[0]); return 1; diff --git a/template/en/default/admin/params/auth.html.tmpl b/template/en/default/admin/params/auth.html.tmpl index 35bddf1af9..8e91e54c0e 100644 --- a/template/en/default/admin/params/auth.html.tmpl +++ b/template/en/default/admin/params/auth.html.tmpl @@ -125,5 +125,17 @@ "default (.*) permits any account matching the emailregexp " _ "to be created. If this parameter is left blank, no users " _ "will be permitted to create their own accounts and all accounts " _ - "will have to be created by an administrator." } + "will have to be created by an administrator.", + + password_complexity => + "Set the complexity required for passwords. In all cases must the passwords " _ + "be at least ${constants.USER_PASSWORD_MIN_LENGTH} characters long." _ + "" + } %] diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index b76106f248..67012b5551 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1325,6 +1325,23 @@ The password must be at least [%+ constants.USER_PASSWORD_MIN_LENGTH FILTER html %] characters long. + [% ELSIF error == "password_not_complex" %] + [% title = "Password Fails Requirements" %] + [% passregex = Param('password_complexity') %] + The password must contain at least one: + + [% ELSIF error == "product_access_denied" %] [% title = "Product Access Denied" %] Either the product