diff options
| author | Simon Josefsson | 2004-10-29 21:21:33 +0000 |
|---|---|---|
| committer | Simon Josefsson | 2004-10-29 21:21:33 +0000 |
| commit | 266725f1a1b41e89d2b4a4d11cb5108bf1d0fb91 (patch) | |
| tree | d1a2bd3a52e6ee24d8e96e288e9d6f341ca4ed59 | |
| parent | f946e47e752c1b3a454f445010da817c7b9f9f00 (diff) | |
| download | emacs-266725f1a1b41e89d2b4a4d11cb5108bf1d0fb91.tar.gz emacs-266725f1a1b41e89d2b4a4d11cb5108bf1d0fb91.zip | |
subr.el (read-passwd): Move back from password.el.
password.el: Remove, not ready yet.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/net/password.el | 184 | ||||
| -rw-r--r-- | lisp/subr.el | 55 |
3 files changed, 61 insertions, 184 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 5bfebecab35..b73f08a9f1f 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2004-10-29 Simon Josefsson <jas@extundo.com> | ||
| 2 | |||
| 3 | * subr.el (read-passwd): Move back from password.el. | ||
| 4 | |||
| 5 | * password.el: Remove, not ready yet. | ||
| 6 | |||
| 1 | 2004-10-29 Andreas Schwab <schwab@suse.de> | 7 | 2004-10-29 Andreas Schwab <schwab@suse.de> |
| 2 | 8 | ||
| 3 | * speedbar.el (speedbar-frame-parameters): Improve customize type. | 9 | * speedbar.el (speedbar-frame-parameters): Improve customize type. |
diff --git a/lisp/net/password.el b/lisp/net/password.el deleted file mode 100644 index da009ed9ea0..00000000000 --- a/lisp/net/password.el +++ /dev/null | |||
| @@ -1,184 +0,0 @@ | |||
| 1 | ;;; password.el --- Read passwords from user, possibly using a password cache. | ||
| 2 | |||
| 3 | ;; Copyright (C) 1999, 2000, 2003, 2004 Free Software Foundation, Inc. | ||
| 4 | |||
| 5 | ;; Author: Simon Josefsson <simon@josefsson.org> | ||
| 6 | ;; Created: 2003-12-21 | ||
| 7 | ;; Keywords: password cache passphrase key | ||
| 8 | |||
| 9 | ;; This file is part of GNU Emacs. | ||
| 10 | |||
| 11 | ;; GNU Emacs is free software; you can redistribute it and/or modify | ||
| 12 | ;; it under the terms of the GNU General Public License as published by | ||
| 13 | ;; the Free Software Foundation; either version 2, or (at your option) | ||
| 14 | ;; any later version. | ||
| 15 | |||
| 16 | ;; GNU Emacs is distributed in the hope that it will be useful, | ||
| 17 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 18 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 19 | ;; GNU General Public License for more details. | ||
| 20 | |||
| 21 | ;; You should have received a copy of the GNU General Public License | ||
| 22 | ;; along with GNU Emacs; see the file COPYING. If not, write to the | ||
| 23 | ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | ||
| 24 | ;; Boston, MA 02111-1307, USA. | ||
| 25 | |||
| 26 | ;;; Commentary: | ||
| 27 | |||
| 28 | ;; Greatly influenced by pgg.el written by Daiki Ueno, with timer | ||
| 29 | ;; fixes for XEmacs by Katsumi Yamaoka. In fact, this is mostly just | ||
| 30 | ;; a rip-off. | ||
| 31 | ;; | ||
| 32 | ;; (password-read "Password? " "test") | ||
| 33 | ;; ;; Minibuffer prompt for password. | ||
| 34 | ;; => "foo" | ||
| 35 | ;; | ||
| 36 | ;; (password-cache-add "test" "foo") | ||
| 37 | ;; => nil | ||
| 38 | |||
| 39 | ;; Note the previous two can be replaced with: | ||
| 40 | ;; (password-read-and-add "Password? " "test") | ||
| 41 | ;; ;; Minibuffer prompt for password. | ||
| 42 | ;; => "foo" | ||
| 43 | ;; ;; "foo" is now cached with key "test" | ||
| 44 | |||
| 45 | |||
| 46 | ;; (password-read "Password? " "test") | ||
| 47 | ;; ;; No minibuffer prompt | ||
| 48 | ;; => "foo" | ||
| 49 | ;; | ||
| 50 | ;; (password-read "Password? " "test") | ||
| 51 | ;; ;; No minibuffer prompt | ||
| 52 | ;; => "foo" | ||
| 53 | ;; | ||
| 54 | ;; ;; Wait `password-cache-expiry' seconds. | ||
| 55 | ;; | ||
| 56 | ;; (password-read "Password? " "test") | ||
| 57 | ;; ;; Minibuffer prompt for password is back. | ||
| 58 | ;; => "foo" | ||
| 59 | |||
| 60 | ;;; Code: | ||
| 61 | |||
| 62 | (when (featurep 'xemacs) | ||
| 63 | (require 'run-at-time)) | ||
| 64 | |||
| 65 | (eval-when-compile | ||
| 66 | (require 'cl)) | ||
| 67 | |||
| 68 | (defcustom password-cache t | ||
| 69 | "Whether to cache passwords." | ||
| 70 | :group 'password | ||
| 71 | :type 'boolean) | ||
| 72 | |||
| 73 | (defcustom password-cache-expiry 16 | ||
| 74 | "How many seconds passwords are cached, or nil to disable expiring. | ||
| 75 | Whether passwords are cached at all is controlled by `password-cache'." | ||
| 76 | :group 'password | ||
| 77 | :type '(choice (const :tag "Never" nil) | ||
| 78 | (integer :tag "Seconds"))) | ||
| 79 | |||
| 80 | (defvar password-data (make-vector 7 0)) | ||
| 81 | |||
| 82 | (defun password-read (prompt &optional key) | ||
| 83 | "Read password, for use with KEY, from user, or from cache if wanted. | ||
| 84 | KEY indicate the purpose of the password, so the cache can | ||
| 85 | separate passwords. The cache is not used if KEY is nil. It is | ||
| 86 | typically a string. | ||
| 87 | The variable `password-cache' control whether the cache is used." | ||
| 88 | (or (and password-cache | ||
| 89 | key | ||
| 90 | (symbol-value (intern-soft key password-data))) | ||
| 91 | (read-passwd prompt))) | ||
| 92 | |||
| 93 | (defun password-read-and-add (prompt &optional key) | ||
| 94 | "Read password, for use with KEY, from user, or from cache if wanted. | ||
| 95 | Then store the password in the cache. Uses `password-read' and | ||
| 96 | `password-cache-add'." | ||
| 97 | (let ((password (password-read prompt key))) | ||
| 98 | (when (and password key) | ||
| 99 | (password-cache-add key password)) | ||
| 100 | password)) | ||
| 101 | |||
| 102 | (defun password-cache-remove (key) | ||
| 103 | "Remove password indexed by KEY from password cache. | ||
| 104 | This is typically run be a timer setup from `password-cache-add', | ||
| 105 | but can be invoked at any time to forcefully remove passwords | ||
| 106 | from the cache. This may be useful when it has been detected | ||
| 107 | that a password is invalid, so that `password-read' query the | ||
| 108 | user again." | ||
| 109 | (let ((password (symbol-value (intern-soft key password-data)))) | ||
| 110 | (when password | ||
| 111 | (fillarray password ?_) | ||
| 112 | (unintern key password-data)))) | ||
| 113 | |||
| 114 | (defun password-cache-add (key password) | ||
| 115 | "Add password to cache. | ||
| 116 | The password is removed by a timer after `password-cache-expiry' | ||
| 117 | seconds." | ||
| 118 | (set (intern key password-data) password) | ||
| 119 | (when password-cache-expiry | ||
| 120 | (run-at-time password-cache-expiry nil | ||
| 121 | #'password-cache-remove | ||
| 122 | key)) | ||
| 123 | nil) | ||
| 124 | |||
| 125 | ;;;###autoload | ||
| 126 | (defun read-passwd (prompt &optional confirm default) | ||
| 127 | "Read a password, prompting with PROMPT, and return it. | ||
| 128 | If optional CONFIRM is non-nil, read the password twice to make sure. | ||
| 129 | Optional DEFAULT is a default password to use instead of empty input. | ||
| 130 | |||
| 131 | This function echoes `.' for each character that the user types. | ||
| 132 | The user ends with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. | ||
| 133 | C-g quits; if `inhibit-quit' was non-nil around this function, | ||
| 134 | then it returns nil if the user types C-g. | ||
| 135 | |||
| 136 | Once the caller uses the password, it can erase the password | ||
| 137 | by doing (clear-string STRING)." | ||
| 138 | (with-local-quit | ||
| 139 | (if confirm | ||
| 140 | (let (success) | ||
| 141 | (while (not success) | ||
| 142 | (let ((first (read-passwd prompt nil default)) | ||
| 143 | (second (read-passwd "Confirm password: " nil default))) | ||
| 144 | (if (equal first second) | ||
| 145 | (progn | ||
| 146 | (and (arrayp second) (clear-string second)) | ||
| 147 | (setq success first)) | ||
| 148 | (and (arrayp first) (clear-string first)) | ||
| 149 | (and (arrayp second) (clear-string second)) | ||
| 150 | (message "Password not repeated accurately; please start over") | ||
| 151 | (sit-for 1)))) | ||
| 152 | success) | ||
| 153 | (let ((pass nil) | ||
| 154 | (c 0) | ||
| 155 | (echo-keystrokes 0) | ||
| 156 | (cursor-in-echo-area t)) | ||
| 157 | (while (progn (message "%s%s" | ||
| 158 | prompt | ||
| 159 | (make-string (length pass) ?.)) | ||
| 160 | (setq c (read-char-exclusive nil t)) | ||
| 161 | (and (/= c ?\r) (/= c ?\n) (/= c ?\e))) | ||
| 162 | (clear-this-command-keys) | ||
| 163 | (if (= c ?\C-u) | ||
| 164 | (progn | ||
| 165 | (and (arrayp pass) (clear-string pass)) | ||
| 166 | (setq pass "")) | ||
| 167 | (if (and (/= c ?\b) (/= c ?\177)) | ||
| 168 | (let* ((new-char (char-to-string c)) | ||
| 169 | (new-pass (concat pass new-char))) | ||
| 170 | (and (arrayp pass) (clear-string pass)) | ||
| 171 | (clear-string new-char) | ||
| 172 | (setq c ?\0) | ||
| 173 | (setq pass new-pass)) | ||
| 174 | (if (> (length pass) 0) | ||
| 175 | (let ((new-pass (substring pass 0 -1))) | ||
| 176 | (and (arrayp pass) (clear-string pass)) | ||
| 177 | (setq pass new-pass)))))) | ||
| 178 | (message nil) | ||
| 179 | (or pass default ""))))) | ||
| 180 | |||
| 181 | (provide 'password) | ||
| 182 | |||
| 183 | ;;; arch-tag: ab160494-16c8-4c68-a4a1-73eebf6686e5 | ||
| 184 | ;;; password.el ends here | ||
diff --git a/lisp/subr.el b/lisp/subr.el index 7a1d32e3979..d84aebceba4 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1215,6 +1215,61 @@ any other non-digit terminates the character code and is then used as input.")) | |||
| 1215 | (setq first nil)) | 1215 | (setq first nil)) |
| 1216 | code)) | 1216 | code)) |
| 1217 | 1217 | ||
| 1218 | (defun read-passwd (prompt &optional confirm default) | ||
| 1219 | "Read a password, prompting with PROMPT, and return it. | ||
| 1220 | If optional CONFIRM is non-nil, read the password twice to make sure. | ||
| 1221 | Optional DEFAULT is a default password to use instead of empty input. | ||
| 1222 | |||
| 1223 | This function echoes `.' for each character that the user types. | ||
| 1224 | The user ends with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. | ||
| 1225 | C-g quits; if `inhibit-quit' was non-nil around this function, | ||
| 1226 | then it returns nil if the user types C-g. | ||
| 1227 | |||
| 1228 | Once the caller uses the password, it can erase the password | ||
| 1229 | by doing (clear-string STRING)." | ||
| 1230 | (with-local-quit | ||
| 1231 | (if confirm | ||
| 1232 | (let (success) | ||
| 1233 | (while (not success) | ||
| 1234 | (let ((first (read-passwd prompt nil default)) | ||
| 1235 | (second (read-passwd "Confirm password: " nil default))) | ||
| 1236 | (if (equal first second) | ||
| 1237 | (progn | ||
| 1238 | (and (arrayp second) (clear-string second)) | ||
| 1239 | (setq success first)) | ||
| 1240 | (and (arrayp first) (clear-string first)) | ||
| 1241 | (and (arrayp second) (clear-string second)) | ||
| 1242 | (message "Password not repeated accurately; please start over") | ||
| 1243 | (sit-for 1)))) | ||
| 1244 | success) | ||
| 1245 | (let ((pass nil) | ||
| 1246 | (c 0) | ||
| 1247 | (echo-keystrokes 0) | ||
| 1248 | (cursor-in-echo-area t)) | ||
| 1249 | (while (progn (message "%s%s" | ||
| 1250 | prompt | ||
| 1251 | (make-string (length pass) ?.)) | ||
| 1252 | (setq c (read-char-exclusive nil t)) | ||
| 1253 | (and (/= c ?\r) (/= c ?\n) (/= c ?\e))) | ||
| 1254 | (clear-this-command-keys) | ||
| 1255 | (if (= c ?\C-u) | ||
| 1256 | (progn | ||
| 1257 | (and (arrayp pass) (clear-string pass)) | ||
| 1258 | (setq pass "")) | ||
| 1259 | (if (and (/= c ?\b) (/= c ?\177)) | ||
| 1260 | (let* ((new-char (char-to-string c)) | ||
| 1261 | (new-pass (concat pass new-char))) | ||
| 1262 | (and (arrayp pass) (clear-string pass)) | ||
| 1263 | (clear-string new-char) | ||
| 1264 | (setq c ?\0) | ||
| 1265 | (setq pass new-pass)) | ||
| 1266 | (if (> (length pass) 0) | ||
| 1267 | (let ((new-pass (substring pass 0 -1))) | ||
| 1268 | (and (arrayp pass) (clear-string pass)) | ||
| 1269 | (setq pass new-pass)))))) | ||
| 1270 | (message nil) | ||
| 1271 | (or pass default ""))))) | ||
| 1272 | |||
| 1218 | ;; This should be used by `call-interactively' for `n' specs. | 1273 | ;; This should be used by `call-interactively' for `n' specs. |
| 1219 | (defun read-number (prompt &optional default) | 1274 | (defun read-number (prompt &optional default) |
| 1220 | (let ((n nil)) | 1275 | (let ((n nil)) |