Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luci: Make password reveal work with password managers #7479

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
ifattr(#self.keylist > 0, "data-choices", { self.keylist, self.vallist })
%> />
<%- if self.password then -%>
<div class="btn cbi-button cbi-button-neutral" title="<%:Reveal/hide password%>" onclick="var e = this.previousElementSibling; e.type = (e.type === 'password') ? 'text' : 'password'">∗</div>
<div class="btn cbi-button cbi-button-neutral" title="<%:Reveal/hide password%>" onclick="var e = this.previousElementSibling; while (e && e.tagName !== 'INPUT') { e = e.previousElementSibling; }; e.type = (e.type === 'password') ? 'text' : 'password'">∗</div>
<% end %>
</div>
14 changes: 12 additions & 2 deletions modules/luci-base/htdocs/luci-static/resources/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -384,8 +384,18 @@ const UITextfield = UIElement.extend(/** @lends LuCI.ui.Textfield.prototype */ {
'title': _('Reveal/hide password'),
'aria-label': _('Reveal/hide password'),
'click': function(ev) {
const e = this.previousElementSibling;
e.type = (e.type === 'password') ? 'text' : 'password';
let e = this.previousElementSibling;
// DOM manipulation (e.g. by password managers) may have inserted other
// elements between the reveal button and the input. This searches for
// the first previous sibling that is also an input.
while (e && e.tagName !== 'INPUT') {
e = e.previousElementSibling;
}
if (e) {
e.type = (e.type === 'password') ? 'text' : 'password';
} else {
console.error("unable to find input corresponding to reveal/hide button");
}
ev.preventDefault();
}
}, '∗')
Expand Down
Loading