<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body style="overflow-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;"><br><div><blockquote type="cite"><div>On 12 Feb 2023, at 11:47, Alessio Stalla <alessiostalla@gmail.com> wrote:</div><br class="Apple-interchange-newline"><div><div dir="ltr"><div>Greetings everyone,</div><div><br></div><div>is there a well-known way to do the thing in the subject, i.e. ask the user for a password in a console application, reading from the keyboard without echoing anything to the terminal? Using a library is fine, SBCL only is fine, limited to some OS is not so fine but better than nothing. Any idea?<br></div></div>
</div></blockquote></div><br><div><br></div><div>Here’s something that I’ve used for Lispworks and SBCL:</div><div><br></div><div><div><br></div><div><font face="Monaco"><span style="font-style: normal;">#+sbcl</span></font></div><div><font face="Monaco"><span style="font-style: normal;">(require :sb-posix)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">#+sbcl</span></font></div><div><font face="Monaco"><span style="font-style: normal;">(defun echo-off ()</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (let ((tm (sb-posix:tcgetattr sb-sys:*tty*)))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (setf (sb-posix:termios-lflag tm)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (logandc2 (sb-posix:termios-lflag tm) sb-posix:echo))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (sb-posix:tcsetattr sb-sys:*tty* sb-posix:tcsanow tm)))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">#+sbcl</span></font></div><div><font face="Monaco"><span style="font-style: normal;">(defun echo-on ()</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (let ((tm (sb-posix:tcgetattr sb-sys:*tty*)))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (setf (sb-posix:termios-lflag tm)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (logior (sb-posix:termios-lflag tm) sb-posix:echo))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (sb-posix:tcsetattr sb-sys:*tty* sb-posix:tcsanow tm)))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">#+sbcl</span></font></div><div><font face="Monaco"><span style="font-style: normal;">(defun prompt-for-value (prompt)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (format t "~&~a " prompt)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (force-output)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (read-line))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">#+sbcl</span></font></div><div><font face="Monaco"><span style="font-style: normal;">(defun prompt-for-value/no-echo (prompt)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (format t "~&~a " prompt)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (force-output)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (echo-off)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (unwind-protect</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (read-line)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (echo-on)))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">#+capi</span></font></div><div><font face="Monaco"><span style="font-style: normal;">(defun prompt-for-value (prompt)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (capi:prompt-for-string prompt))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">#+capi</span></font></div><div><font face="Monaco"><span style="font-style: normal;">(defun prompt-for-value/no-echo (prompt)</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (capi:prompt-for-string prompt :pane-class 'capi:password-pane))</span></font></div><div><font face="Monaco"><span style="font-style: normal;"><br></span></font></div><div><font face="Monaco"><span style="font-style: normal;">(defun get-passphrase-from-user ()</span></font></div><div><font face="Monaco"><span style="font-style: normal;"> (prompt-for-value/no-echo "Passphrase?"))</span></font></div></div><div><br></div></body></html>