changeset 21092:7726f8d9eff0

(read-passwd): Renamed from read-password. New second arg CONFIRM.
author Richard M. Stallman <rms@gnu.org>
date Sun, 08 Mar 1998 00:16:38 +0000
parents 70301d94ce1e
children aa96b119d0ef
files lisp/subr.el
diffstat 1 files changed, 31 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/subr.el	Sat Mar 07 22:34:50 1998 +0000
+++ b/lisp/subr.el	Sun Mar 08 00:16:38 1998 +0000
@@ -763,27 +763,38 @@
       (setq first nil))
     code))
 
-(defun read-password (prompt &optional default)
-  "Read a password, echoing `.' for each character typed.
+(defun read-passwd (prompt &optional confirm default)
+  "Read a password, prompting with PROMPT.  Echo `.' for each character typed.
 End with RET, LFD, or ESC.  DEL or C-h rubs out.  C-u kills line.
-Optional DEFAULT is password to start with."
-  (let ((pass nil)
-	(c 0)
-	(echo-keystrokes 0)
-	(cursor-in-echo-area t))
-    (while (progn (message "%s%s"
-			   prompt
-			   (make-string (length pass) ?.))
-		  (setq c (read-char))
-		  (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
-      (if (= c ?\C-u)
-	  (setq pass "")
-	(if (and (/= c ?\b) (/= c ?\177))
-	    (setq pass (concat pass (char-to-string c)))
-	  (if (> (length pass) 0)
-	      (setq pass (substring pass 0 -1))))))
-    (message nil)
-    (or pass default "")))
+Optional argument CONFIRM, if non-nil, then read it twice to make sure.
+Optional DEFAULT is a default password to use instead of empty input."
+  (if confirm
+      (let (success)
+	(while (not success)
+	  (let ((first (read-passwd prompt nil default))
+		(second (read-passwd "Confirm password: " nil default)))
+	    (if (equal first second)
+		(setq success first)
+	      (message "Password not repeated accurately; please start over")
+	      (sit-for 1))))
+	success)
+    (let ((pass nil)
+	  (c 0)
+	  (echo-keystrokes 0)
+	  (cursor-in-echo-area t))
+      (while (progn (message "%s%s"
+			     prompt
+			     (make-string (length pass) ?.))
+		    (setq c (read-char))
+		    (and (/= c ?\r) (/= c ?\n) (/= c ?\e)))
+	(if (= c ?\C-u)
+	    (setq pass "")
+	  (if (and (/= c ?\b) (/= c ?\177))
+	      (setq pass (concat pass (char-to-string c)))
+	    (if (> (length pass) 0)
+		(setq pass (substring pass 0 -1))))))
+      (message nil)
+      (or pass default ""))))
 
 (defun force-mode-line-update (&optional all)
   "Force the mode-line of the current buffer to be redisplayed.