Skip to content

Commit a6e5304

Browse files
author
Marius Burkard
committed
- switch password field to hidden on input (Fixes #3401)
1 parent cffa2fa commit a6e5304

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

interface/web/js/scrigo.js.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,12 @@ function generatePassword(passwordFieldID, repeatPasswordFieldID){
204204
var pword = password(<?php echo $min_password_length; ?>, false, 1);
205205
jQuery('#'+repeatPasswordFieldID).val(pword);
206206
newPWField.attr('id', passwordFieldID).val(pword).trigger('keyup').select();
207+
newPWField.unbind('keyup').on('keyup', function(e) {
208+
if($(this).val() != pword) {
209+
var pos = $(this).getCursorPosition();
210+
$(this).attr('type', 'password').unbind('keyup').setCursorPosition(pos);
211+
}
212+
});
207213
}
208214

209215
var funcDisableClick = function(e) { e.preventDefault(); return false; };

interface/web/themes/default/assets/javascripts/ispconfig.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,4 +747,35 @@ $(document).on('ready', function () {
747747
e.preventDefault();
748748
}
749749
});
750+
751+
$.fn.setCursorPosition = function(pos) {
752+
var self = $(this).get(0);
753+
if(self.setSelectionRange) {
754+
self.setSelectionRange(pos, pos);
755+
} else if(self.createTextRange) {
756+
var range = self.createTextRange();
757+
range.collapse(true);
758+
if(pos < 0) {
759+
pos = $(this).val().length + pos;
760+
}
761+
range.moveEnd('character', pos);
762+
range.moveStart('character', pos);
763+
range.select();
764+
}
765+
};
766+
767+
$.fn.getCursorPosition = function() {
768+
var iCaretPos = 0;
769+
var self = $(this).get(0);
770+
771+
if(typeof self.selectionStart === 'number') {
772+
iCaretPos = self.selectionDirection == 'backward' ? self.selectionStart : self.selectionEnd;
773+
} else if(document.selection) {
774+
this.focus();
775+
var oSel = document.selection.createRange();
776+
oSel.moveStart('character', -self.value.length);
777+
iCaretPos = oSel.text.length;
778+
}
779+
return iCaretPos;
780+
};
750781
});

0 commit comments

Comments
 (0)