diff options
| author | Simon Josefsson | 2004-10-25 13:22:17 +0000 |
|---|---|---|
| committer | Simon Josefsson | 2004-10-25 13:22:17 +0000 |
| commit | d7aea840359e05e76a38b9930980d9334c67ceb4 (patch) | |
| tree | 545119e1f5cd19c549dfe176c59e95ecd3120ac0 | |
| parent | 85af630d59f4e4bc75fc9cbbe341198ff31f4aaa (diff) | |
| download | emacs-d7aea840359e05e76a38b9930980d9334c67ceb4.tar.gz emacs-d7aea840359e05e76a38b9930980d9334c67ceb4.zip | |
* subr.el (read-passwd): Move to net/password.el.
* net/password.el (read-passwd): Add. Autoload it.
| -rw-r--r-- | lisp/ChangeLog | 6 | ||||
| -rw-r--r-- | lisp/net/password.el | 56 | ||||
| -rw-r--r-- | lisp/subr.el | 55 |
3 files changed, 62 insertions, 55 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 21db50ad564..789e675d1b4 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog | |||
| @@ -1,3 +1,9 @@ | |||
| 1 | 2004-10-25 Simon Josefsson <jas@extundo.com> | ||
| 2 | |||
| 3 | * subr.el (read-passwd): Move to net/password.el. | ||
| 4 | |||
| 5 | * net/password.el (read-passwd): Add. Autoload it. | ||
| 6 | |||
| 1 | 2004-10-25 Kai Grossjohann <kai.grossjohann@gmx.net> | 7 | 2004-10-25 Kai Grossjohann <kai.grossjohann@gmx.net> |
| 2 | 8 | ||
| 3 | * mouse-sel.el (mouse-sel-mode): Specify custom group. | 9 | * mouse-sel.el (mouse-sel-mode): Specify custom group. |
diff --git a/lisp/net/password.el b/lisp/net/password.el index e8be612ecca..da009ed9ea0 100644 --- a/lisp/net/password.el +++ b/lisp/net/password.el | |||
| @@ -122,6 +122,62 @@ seconds." | |||
| 122 | key)) | 122 | key)) |
| 123 | nil) | 123 | nil) |
| 124 | 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 | |||
| 125 | (provide 'password) | 181 | (provide 'password) |
| 126 | 182 | ||
| 127 | ;;; arch-tag: ab160494-16c8-4c68-a4a1-73eebf6686e5 | 183 | ;;; arch-tag: ab160494-16c8-4c68-a4a1-73eebf6686e5 |
diff --git a/lisp/subr.el b/lisp/subr.el index b137e7fdfd7..ee0823c89e6 100644 --- a/lisp/subr.el +++ b/lisp/subr.el | |||
| @@ -1211,61 +1211,6 @@ any other non-digit terminates the character code and is then used as input.")) | |||
| 1211 | (setq first nil)) | 1211 | (setq first nil)) |
| 1212 | code)) | 1212 | code)) |
| 1213 | 1213 | ||
| 1214 | (defun read-passwd (prompt &optional confirm default) | ||
| 1215 | "Read a password, prompting with PROMPT, and return it. | ||
| 1216 | If optional CONFIRM is non-nil, read the password twice to make sure. | ||
| 1217 | Optional DEFAULT is a default password to use instead of empty input. | ||
| 1218 | |||
| 1219 | This function echoes `.' for each character that the user types. | ||
| 1220 | The user ends with RET, LFD, or ESC. DEL or C-h rubs out. C-u kills line. | ||
| 1221 | C-g quits; if `inhibit-quit' was non-nil around this function, | ||
| 1222 | then it returns nil if the user types C-g. | ||
| 1223 | |||
| 1224 | Once the caller uses the password, it can erase the password | ||
| 1225 | by doing (clear-string STRING)." | ||
| 1226 | (with-local-quit | ||
| 1227 | (if confirm | ||
| 1228 | (let (success) | ||
| 1229 | (while (not success) | ||
| 1230 | (let ((first (read-passwd prompt nil default)) | ||
| 1231 | (second (read-passwd "Confirm password: " nil default))) | ||
| 1232 | (if (equal first second) | ||
| 1233 | (progn | ||
| 1234 | (and (arrayp second) (clear-string second)) | ||
| 1235 | (setq success first)) | ||
| 1236 | (and (arrayp first) (clear-string first)) | ||
| 1237 | (and (arrayp second) (clear-string second)) | ||
| 1238 | (message "Password not repeated accurately; please start over") | ||
| 1239 | (sit-for 1)))) | ||
| 1240 | success) | ||
| 1241 | (let ((pass nil) | ||
| 1242 | (c 0) | ||
| 1243 | (echo-keystrokes 0) | ||
| 1244 | (cursor-in-echo-area t)) | ||
| 1245 | (while (progn (message "%s%s" | ||
| 1246 | prompt | ||
| 1247 | (make-string (length pass) ?.)) | ||
| 1248 | (setq c (read-char-exclusive nil t)) | ||
| 1249 | (and (/= c ?\r) (/= c ?\n) (/= c ?\e))) | ||
| 1250 | (clear-this-command-keys) | ||
| 1251 | (if (= c ?\C-u) | ||
| 1252 | (progn | ||
| 1253 | (and (arrayp pass) (clear-string pass)) | ||
| 1254 | (setq pass "")) | ||
| 1255 | (if (and (/= c ?\b) (/= c ?\177)) | ||
| 1256 | (let* ((new-char (char-to-string c)) | ||
| 1257 | (new-pass (concat pass new-char))) | ||
| 1258 | (and (arrayp pass) (clear-string pass)) | ||
| 1259 | (clear-string new-char) | ||
| 1260 | (setq c ?\0) | ||
| 1261 | (setq pass new-pass)) | ||
| 1262 | (if (> (length pass) 0) | ||
| 1263 | (let ((new-pass (substring pass 0 -1))) | ||
| 1264 | (and (arrayp pass) (clear-string pass)) | ||
| 1265 | (setq pass new-pass)))))) | ||
| 1266 | (message nil) | ||
| 1267 | (or pass default ""))))) | ||
| 1268 | |||
| 1269 | ;; This should be used by `call-interactively' for `n' specs. | 1214 | ;; This should be used by `call-interactively' for `n' specs. |
| 1270 | (defun read-number (prompt &optional default) | 1215 | (defun read-number (prompt &optional default) |
| 1271 | (let ((n nil)) | 1216 | (let ((n nil)) |