🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.emacs
Article #2183

Re: getpass needed

#2183
From: Matthew P Wiener
Date: Fri, 24 Oct 1986 18:19
44 lines
2601 bytes
Note-I originally posted an erroneous version, now cancelled.

In article <6431@topaz.RUTGERS.EDU> lear@topaz.RUTGERS.EDU (eliot lear) writes:
>Hi..  I am a relative novice working with emacs and was wondering
>if there is a method available from gnu to turn off echo (preferably
>in the minibuffer).  Reason I ask is that I am attempting to write
>some form of library for encrypted files.

The following library should do the trick.  You turn off echoing by binding
the individual letters yourself.  Just load the library, and then invoke with
(read-string-no-echo "Key: ") or whatever prompt you wish to use.

ucbvax!brahms!weemba	Matthew P Wiener/UCB Math Dept/Berkeley CA 94720
Without NNTP, the brahms gang itself would be impossible.  --Erik E Fair
------------------------------------------------------------------------
;;; GNU Emacs library to read in passwords from the minibuffer
;;; Standard GNU copying privileges apply

;; We need to define our own minibuffer keymap.
(setq minibuffer-local-no-echo-map (copy-keymap minibuffer-local-map))

;; We trap all printing characters.
(let ((i ?\040))
  (while (< i ?\177)
    (nconc minibuffer-local-no-echo-map (list (cons i 'read-char-no-echo)))
    (setq i (1+ i))))

;; We provide for the delete character.
(nconc minibuffer-local-no-echo-map '((?\177 . delete-char-no-echo)))

;; This function squirrels each typed-in character away.
(defun read-char-no-echo () (interactive)
  (setq no-echo-list (append no-echo-list (list (this-command-keys)))))

;; This function erases the last character from the input list.
(defun delete-char-no-echo () (interactive)
  (setq no-echo-list (nreverse (cdr (nreverse no-echo-list)))))

;; This is the function the user actually uses.
(defun read-string-no-echo (prompt)
  "Get a password from the minibuffer, prompting with PROMPT."
  (let (no-echo-list)
    (read-from-minibuffer prompt nil minibuffer-local-no-echo-map)
    (mapconcat 'identity no-echo-list nil)))
Technical Details
Message-ID: <69@cartan.Berkeley.EDU>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!nike!ucbcad!ucbvax!cartan!brahms!weemba
References: <6431@topaz.RUTGERS.EDU>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!rutgers!nike!ucbcad!ucbvax!cartan!brahms!weemba
From: weemba@brahms (Matthew P Wiener)
Newsgroups: net.emacs
Subject: Re: getpass needed
Message-ID: <69@cartan.Berkeley.EDU>
Date: Fri, 24-Oct-86 14:19:03 EDT
Article-I.D.: cartan.69
Posted: Fri Oct 24 14:19:03 1986
Date-Received: Sat, 25-Oct-86 07:15:22 EDT
References: <6431@topaz.RUTGERS.EDU>
Sender: daemon@cartan.Berkeley.EDU
Reply-To: weemba@brahms.BERKELEY.EDU (Matthew P Wiener)
Organization: University of California, Berkeley
Lines: 44