aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Ingebrigtsen2019-10-13 05:15:18 +0200
committerLars Ingebrigtsen2019-10-13 05:15:18 +0200
commitde88ed8646383301f20f8340e13d43e5918310fa (patch)
tree3b9e7ebebeac8d956b36ebfb8c912ebbddeb8e28
parent4d74b2b9539964758fc433480ad93ce912b6f3db (diff)
downloademacs-de88ed8646383301f20f8340e13d43e5918310fa.tar.gz
emacs-de88ed8646383301f20f8340e13d43e5918310fa.zip
Hide passwords more in `read-password'
* lisp/subr.el (read-password--hide-password): Factor out (bug#17127). (read-passwd): Use it in post-command-hook instead of after-change-functions to ensure that we hide the password no matter what inserts text.
-rw-r--r--lisp/subr.el21
1 files changed, 10 insertions, 11 deletions
diff --git a/lisp/subr.el b/lisp/subr.el
index 76b0e4b3944..1a4a2e8b81b 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2463,6 +2463,12 @@ some sort of escape sequence, the ambiguity is resolved via `read-key-delay'."
2463 map) 2463 map)
2464 "Keymap used while reading passwords.") 2464 "Keymap used while reading passwords.")
2465 2465
2466(defun read-password--hide-password ()
2467 (let ((beg (minibuffer-prompt-end)))
2468 (dotimes (i (1+ (- (buffer-size) beg)))
2469 (put-text-property (+ i beg) (+ 1 i beg)
2470 'display (string (or read-hide-char ?*))))))
2471
2466(defun read-passwd (prompt &optional confirm default) 2472(defun read-passwd (prompt &optional confirm default)
2467 "Read a password, prompting with PROMPT, and return it. 2473 "Read a password, prompting with PROMPT, and return it.
2468If optional CONFIRM is non-nil, read the password twice to make sure. 2474If optional CONFIRM is non-nil, read the password twice to make sure.
@@ -2487,15 +2493,7 @@ by doing (clear-string STRING)."
2487 (message "Password not repeated accurately; please start over") 2493 (message "Password not repeated accurately; please start over")
2488 (sit-for 1)))) 2494 (sit-for 1))))
2489 success) 2495 success)
2490 (let ((hide-chars-fun 2496 (let (minibuf)
2491 (lambda (beg end _len)
2492 (clear-this-command-keys)
2493 (setq beg (min end (max (minibuffer-prompt-end)
2494 beg)))
2495 (dotimes (i (- end beg))
2496 (put-text-property (+ i beg) (+ 1 i beg)
2497 'display (string (or read-hide-char ?*))))))
2498 minibuf)
2499 (minibuffer-with-setup-hook 2497 (minibuffer-with-setup-hook
2500 (lambda () 2498 (lambda ()
2501 (setq minibuf (current-buffer)) 2499 (setq minibuf (current-buffer))
@@ -2506,7 +2504,7 @@ by doing (clear-string STRING)."
2506 (use-local-map read-passwd-map) 2504 (use-local-map read-passwd-map)
2507 (setq-local inhibit-modification-hooks nil) ;bug#15501. 2505 (setq-local inhibit-modification-hooks nil) ;bug#15501.
2508 (setq-local show-paren-mode nil) ;bug#16091. 2506 (setq-local show-paren-mode nil) ;bug#16091.
2509 (add-hook 'after-change-functions hide-chars-fun nil 'local)) 2507 (add-hook 'post-command-hook 'read-password--hide-password nil t))
2510 (unwind-protect 2508 (unwind-protect
2511 (let ((enable-recursive-minibuffers t) 2509 (let ((enable-recursive-minibuffers t)
2512 (read-hide-char (or read-hide-char ?*))) 2510 (read-hide-char (or read-hide-char ?*)))
@@ -2516,7 +2514,8 @@ by doing (clear-string STRING)."
2516 ;; Not sure why but it seems that there might be cases where the 2514 ;; Not sure why but it seems that there might be cases where the
2517 ;; minibuffer is not always properly reset later on, so undo 2515 ;; minibuffer is not always properly reset later on, so undo
2518 ;; whatever we've done here (bug#11392). 2516 ;; whatever we've done here (bug#11392).
2519 (remove-hook 'after-change-functions hide-chars-fun 'local) 2517 (remove-hook 'after-change-functions 'read-password--hide-password
2518 'local)
2520 (kill-local-variable 'post-self-insert-hook) 2519 (kill-local-variable 'post-self-insert-hook)
2521 ;; And of course, don't keep the sensitive data around. 2520 ;; And of course, don't keep the sensitive data around.
2522 (erase-buffer)))))))) 2521 (erase-buffer))))))))