mirror of
https://github.com/processwire/processwire.git
synced 2025-08-09 16:26:59 +02:00
Fix issue processwire/processwire-issues#239 (display Password description and notes in correct locations). Plus add support for disabling and/or relaxing some of the strict password requirements per a previous request (which I can't seem to find at the moment).
This commit is contained in:
@@ -56,6 +56,12 @@ class InputfieldPassword extends InputfieldText {
|
||||
*/
|
||||
const requireOther = 'other';
|
||||
|
||||
/**
|
||||
* Requirements: disable all above
|
||||
*
|
||||
*/
|
||||
const requireNone = 'none';
|
||||
|
||||
/**
|
||||
* Require old password before changes? Auto
|
||||
*
|
||||
@@ -102,6 +108,7 @@ class InputfieldPassword extends InputfieldText {
|
||||
self::requireUpperLetter => $this->_('uppercase letter'),
|
||||
self::requireDigit => $this->_('digit'),
|
||||
self::requireOther => $this->_('symbol/punctuation'),
|
||||
self::requireNone => $this->_('none (disable all above)'),
|
||||
));
|
||||
$this->set('showPass', false); // allow password to be rendered in renderValue and/or re-populated in form?
|
||||
}
|
||||
@@ -158,8 +165,6 @@ class InputfieldPassword extends InputfieldText {
|
||||
*/
|
||||
public function ___render() {
|
||||
|
||||
$description = $this->getSetting('description');
|
||||
if($description) $this->notes = $description;
|
||||
|
||||
$minlength = (int) $this->attr('minlength');
|
||||
$requirements = array();
|
||||
@@ -168,15 +173,18 @@ class InputfieldPassword extends InputfieldText {
|
||||
sprintf($this->_('at least %d characters long'), $minlength) . "[/span]";
|
||||
}
|
||||
$labels = $this->getSetting('requirementsLabels');
|
||||
if(!in_array(self::requireNone, $this->getSetting('requirements'))) {
|
||||
foreach($this->getSetting('requirements') as $name) {
|
||||
$requirements[$name] = "[span.pass-require.pass-require-$name]" . $labels[$name] . "[/span]";
|
||||
}
|
||||
}
|
||||
if(isset($requirements['upper']) || isset($requirements['lower'])) {
|
||||
unset($requirements['letter']);
|
||||
}
|
||||
if(count($requirements)) {
|
||||
$description = implode(", ", $requirements);
|
||||
$description = sprintf($this->_('Minimum requirements: %s.'), $description);
|
||||
$description = trim("$description " . $this->getSetting('description'));
|
||||
$this->set('description', $description);
|
||||
}
|
||||
|
||||
@@ -193,7 +201,7 @@ class InputfieldPassword extends InputfieldText {
|
||||
}
|
||||
|
||||
$this->attr('data-banMode', $this->complexifyBanMode ? $this->complexifyBanMode : 'loose');
|
||||
$this->attr('data-factor', $this->complexifyFactor ? $this->complexifyFactor : '0.7');
|
||||
$this->attr('data-factor', (float) $this->complexifyFactor >= 0 ? $this->complexifyFactor : 0);
|
||||
|
||||
$inputClass = $this->wire('sanitizer')->entities($this->attr('class'));
|
||||
$this->addClass('InputfieldPasswordComplexify');
|
||||
@@ -369,6 +377,11 @@ class InputfieldPassword extends InputfieldText {
|
||||
$numErrors++;
|
||||
}
|
||||
|
||||
if(in_array(self::requireNone, $requirements)) {
|
||||
// early exit if all following requirements are disabled
|
||||
return $numErrors === 0;
|
||||
}
|
||||
|
||||
if(in_array(self::requireLetter, $requirements)) {
|
||||
// if(!preg_match('/[a-zA-Z]/', $value)) {
|
||||
if(!preg_match('/\p{L}/', $value)) {
|
||||
@@ -441,7 +454,9 @@ class InputfieldPassword extends InputfieldText {
|
||||
foreach($this->getSetting('requirementsLabels') as $value => $label) {
|
||||
$f->addOption($value, $label);
|
||||
}
|
||||
$f->attr('value', $this->getSetting('requirements'));
|
||||
$value = $this->getSetting('requirements');
|
||||
if(in_array(self::requireNone, $value)) $value = array('none');
|
||||
$f->attr('value', $value);
|
||||
$f->columnWidth = 50;
|
||||
$inputfields->add($f);
|
||||
|
||||
@@ -459,6 +474,7 @@ class InputfieldPassword extends InputfieldText {
|
||||
$f->attr('name', 'complexifyFactor');
|
||||
$f->label = $this->_('Complexify factor');
|
||||
$f->description = $this->_('Lower numbers allow weaker passwords, higher numbers require stronger passwords.');
|
||||
$f->description .= ' ' . $this->_('Specify -1 to disable this feature.');
|
||||
$f->notes = $this->_('We recommend something between 0.5 and 1.0');
|
||||
$f->attr('value', $this->complexifyFactor);
|
||||
$f->columnWidth = 50;
|
||||
@@ -468,6 +484,7 @@ class InputfieldPassword extends InputfieldText {
|
||||
$f->attr('name', 'minlength');
|
||||
$f->label = $this->_('Minimum password length');
|
||||
$f->attr('value', $this->attr('minlength'));
|
||||
$f->attr('min', 3);
|
||||
$f->columnWidth = 50;
|
||||
$inputfields->add($f);
|
||||
|
||||
|
Reference in New Issue
Block a user