/[emacs]/emacs/lisp/net/password.el
ViewVC logotype

Diff of /emacs/lisp/net/password.el

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jas, Fri Oct 15 19:35:38 2004 UTC revision 1.2 by jas, Mon Oct 25 13:21:58 2004 UTC
# Line 122  seconds." Line 122  seconds."
122                   key))                   key))
123    nil)    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)  (provide 'password)
182    
183  ;;; arch-tag: ab160494-16c8-4c68-a4a1-73eebf6686e5  ;;; arch-tag: ab160494-16c8-4c68-a4a1-73eebf6686e5

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26