Skip to content

Commit 8226c66

Browse files
committed
Touch up PW validator code (rename variables for clarity, reduce nesting)
1 parent edc9710 commit 8226c66

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

src/modules/security.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,35 +33,36 @@
3333
});
3434

3535
/*
36-
* Validate confirmation
36+
* Validate confirmation (tests that two inputs are identical; usually used for
37+
* passwords)
3738
*/
3839
$.formUtils.addValidator({
3940
name : 'confirmation',
4041
validatorFunction : function(value, $el, config, language, $form) {
41-
var conf = '',
42-
confInputName = $el.valAttr('confirm') || ($el.attr('name') + '_confirmation'),
43-
$confInput = $form.find('[name="' +confInputName+ '"]').eq(0);
44-
45-
if ($confInput.length) {
46-
conf = $confInput.val();
47-
if( config.validateOnBlur && !$confInput[0].hasValidationCallback ) {
48-
$confInput[0].hasValidationCallback = true;
49-
var keyUpCallback = function() {
50-
$el.validate();
51-
};
52-
$confInput.on('keyup', keyUpCallback);
53-
$form.one('formValidationSetup', function() {
54-
$confInput[0].hasValidationCallback = false;
55-
$confInput.off('keyup', keyUpCallback);
56-
});
57-
}
58-
} else {
42+
var password,
43+
passwordInputName = $el.valAttr('confirm') ||
44+
($el.attr('name') + '_confirmation'),
45+
$passwordInput = $form.find('[name="' +passwordInputName+ '"]');
46+
if (!$passwordInput.length) {
5947
$.formUtils.warn('Password confirmation validator: could not find an input ' +
60-
'with name "'+confInputName+'"');
48+
'with name "'+passwordInputName+'"');
6149
return false;
6250
}
6351

64-
return value === conf;
52+
password = $passwordInput.val();
53+
if( config.validateOnBlur && !$passwordInput[0].hasValidationCallback ) {
54+
$passwordInput[0].hasValidationCallback = true;
55+
var keyUpCallback = function() {
56+
$el.validate();
57+
};
58+
$passwordInput.on('keyup', keyUpCallback);
59+
$form.one('formValidationSetup', function() {
60+
$passwordInput[0].hasValidationCallback = false;
61+
$passwordInput.off('keyup', keyUpCallback);
62+
});
63+
}
64+
65+
return value === password;
6566
},
6667
errorMessage : '',
6768
errorMessageKey: 'notConfirmed'

0 commit comments

Comments
 (0)