emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: better than read-hide-char


From: Stefan Monnier
Subject: Re: better than read-hide-char
Date: Tue, 31 Jul 2018 09:47:56 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux)

> the password echoes as 012345678901234567890123456789...
> That way, you could tell how many characters you have successfully typed
> even when they are 20, 30, 40, 50, 60 or 70 characters.
> That would help people notice some mistakes in long passwords.

Sure.  Another option would be the patch below.
BTW, for those who like to have their password sanity-checked locally
before they press RET, it even displays some kind of short hash ;-)


        Stefan


PS: Adding a command to temporarily reveal the password is also a small
matter of programming.


diff --git a/lisp/subr.el b/lisp/subr.el
index 5b38c4d42e..d93b97a7c4 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -2452,11 +2452,19 @@
               (message "Password not repeated accurately; please start over")
               (sit-for 1))))
         success)
-    (let ((hide-chars-fun
+    (let* (ol
+           (hide-chars-fun
            (lambda (beg end _len)
              (clear-this-command-keys)
              (setq beg (min end (max (minibuffer-prompt-end)
                                      beg)))
+              (move-overlay ol (point-max) (point-max))
+              (let ((len (- (point-max) (minibuffer-prompt-end)))
+                    (hash (md5 (minibuffer-contents-no-properties))))
+                (overlay-put ol 'after-string
+                             (if (> len 1)
+                                 (format "  [%d chars, #%s]"
+                                         len (substring hash 0 4)))))
              (dotimes (i (- end beg))
                (put-text-property (+ i beg) (+ 1 i beg)
                                   'display (string (or read-hide-char ?.))))))
@@ -2471,6 +2479,7 @@ read-passwd
             (use-local-map read-passwd-map)
             (setq-local inhibit-modification-hooks nil) ;bug#15501.
            (setq-local show-paren-mode nil)            ;bug#16091.
+            (setq ol (make-overlay (point-max) (point-max) nil t t))
             (add-hook 'after-change-functions hide-chars-fun nil 'local))
         (unwind-protect
             (let ((enable-recursive-minibuffers t)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]