@@ -4749,32 +4749,38 @@ function get_complete_user_data($field, $value, $mnethostid = null) {
47494749function check_password_policy ($ password , &$ errmsg ) {
47504750 global $ CFG ;
47514751
4752- if (empty ($ CFG ->passwordpolicy )) {
4753- return true ;
4754- }
4755-
4756- $ errmsg = '' ;
4757- if (core_text::strlen ($ password ) < $ CFG ->minpasswordlength ) {
4758- $ errmsg .= '<div> ' . get_string ('errorminpasswordlength ' , 'auth ' , $ CFG ->minpasswordlength ) .'</div> ' ;
4759-
4760- }
4761- if (preg_match_all ('/[[:digit:]]/u ' , $ password , $ matches ) < $ CFG ->minpassworddigits ) {
4762- $ errmsg .= '<div> ' . get_string ('errorminpassworddigits ' , 'auth ' , $ CFG ->minpassworddigits ) .'</div> ' ;
4763-
4764- }
4765- if (preg_match_all ('/[[:lower:]]/u ' , $ password , $ matches ) < $ CFG ->minpasswordlower ) {
4766- $ errmsg .= '<div> ' . get_string ('errorminpasswordlower ' , 'auth ' , $ CFG ->minpasswordlower ) .'</div> ' ;
4767-
4752+ if (!empty ($ CFG ->passwordpolicy )) {
4753+ $ errmsg = '' ;
4754+ if (core_text::strlen ($ password ) < $ CFG ->minpasswordlength ) {
4755+ $ errmsg .= '<div> ' . get_string ('errorminpasswordlength ' , 'auth ' , $ CFG ->minpasswordlength ) .'</div> ' ;
4756+ }
4757+ if (preg_match_all ('/[[:digit:]]/u ' , $ password , $ matches ) < $ CFG ->minpassworddigits ) {
4758+ $ errmsg .= '<div> ' . get_string ('errorminpassworddigits ' , 'auth ' , $ CFG ->minpassworddigits ) .'</div> ' ;
4759+ }
4760+ if (preg_match_all ('/[[:lower:]]/u ' , $ password , $ matches ) < $ CFG ->minpasswordlower ) {
4761+ $ errmsg .= '<div> ' . get_string ('errorminpasswordlower ' , 'auth ' , $ CFG ->minpasswordlower ) .'</div> ' ;
4762+ }
4763+ if (preg_match_all ('/[[:upper:]]/u ' , $ password , $ matches ) < $ CFG ->minpasswordupper ) {
4764+ $ errmsg .= '<div> ' . get_string ('errorminpasswordupper ' , 'auth ' , $ CFG ->minpasswordupper ) .'</div> ' ;
4765+ }
4766+ if (preg_match_all ('/[^[:upper:][:lower:][:digit:]]/u ' , $ password , $ matches ) < $ CFG ->minpasswordnonalphanum ) {
4767+ $ errmsg .= '<div> ' . get_string ('errorminpasswordnonalphanum ' , 'auth ' , $ CFG ->minpasswordnonalphanum ) .'</div> ' ;
4768+ }
4769+ if (!check_consecutive_identical_characters ($ password , $ CFG ->maxconsecutiveidentchars )) {
4770+ $ errmsg .= '<div> ' . get_string ('errormaxconsecutiveidentchars ' , 'auth ' , $ CFG ->maxconsecutiveidentchars ) .'</div> ' ;
4771+ }
47684772 }
4769- if (preg_match_all ('/[[:upper:]]/u ' , $ password , $ matches ) < $ CFG ->minpasswordupper ) {
4770- $ errmsg .= '<div> ' . get_string ('errorminpasswordupper ' , 'auth ' , $ CFG ->minpasswordupper ) .'</div> ' ;
47714773
4772- }
4773- if (preg_match_all ('/[^[:upper:][:lower:][:digit:]]/u ' , $ password , $ matches ) < $ CFG ->minpasswordnonalphanum ) {
4774- $ errmsg .= '<div> ' . get_string ('errorminpasswordnonalphanum ' , 'auth ' , $ CFG ->minpasswordnonalphanum ) .'</div> ' ;
4775- }
4776- if (!check_consecutive_identical_characters ($ password , $ CFG ->maxconsecutiveidentchars )) {
4777- $ errmsg .= '<div> ' . get_string ('errormaxconsecutiveidentchars ' , 'auth ' , $ CFG ->maxconsecutiveidentchars ) .'</div> ' ;
4774+ // Fire any additional password policy functions from plugins.
4775+ // Plugin functions should output an error message string or empty string for success.
4776+ $ pluginsfunction = get_plugins_with_function ('check_password_policy ' );
4777+ foreach ($ pluginsfunction as $ plugintype => $ plugins ) {
4778+ foreach ($ plugins as $ pluginfunction ) {
4779+ $ pluginerr = $ pluginfunction ($ password );
4780+ if ($ pluginerr ) {
4781+ $ errmsg .= '<div> ' . $ pluginerr .'</div> ' ;
4782+ }
4783+ }
47784784 }
47794785
47804786 if ($ errmsg == '' ) {
0 commit comments