Skip to content

Commit

Permalink
MDL-36056 form: Do not allow passwords with wrapping whitespace
Browse files Browse the repository at this point in the history
This is to avoid accidental misconfiguration while copy/pasting the
password value.
  • Loading branch information
mudrd8mz committed Nov 30, 2017
1 parent 5bde2c2 commit 0c6554e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions lang/en/form.php
Expand Up @@ -41,6 +41,7 @@
$string['err_numeric'] = 'You must enter a number here.';
$string['err_rangelength'] = 'You must enter between {$a->format[0]} and {$a->format[1]} characters here.';
$string['err_required'] = 'You must supply a value here.';
$string['err_wrappingwhitespace'] = 'The value must not start or end with whitespace.';
$string['err_wrongfileextension'] = 'Some files ({$a->wrongfiles}) cannot be uploaded. Only file types {$a->whitelist} are allowed.';
$string['filesofthesetypes'] = 'Accepted file types:';
$string['filetypesany'] = 'All file types';
Expand Down
18 changes: 18 additions & 0 deletions lib/form/passwordunmask.php
Expand Up @@ -90,4 +90,22 @@ public function export_for_template(renderer_base $output) {

return $context;
}

/**
* Check that there is no whitespace at the beginning and end of the password.
*
* It turned out that wrapping whitespace can easily be pasted by accident when copying the text from elsewhere.
* Such a mistake is very hard to debug as the whitespace is not displayed.
*
* @param array $value Submitted value.
* @return string|null Validation error message or null.
*/
public function validateSubmitValue($value) {

if ($value !== trim($value)) {
return get_string('err_wrappingwhitespace', 'core_form');
}

return;
}
}

0 comments on commit 0c6554e

Please sign in to comment.