Password input in a console application
Kevin Layer
layer at franz.com
Fri Apr 21 16:49:32 UTC 2023
Raymond Wiker wrote:
>>
>> > On 12 Feb 2023, at 11:47, Alessio Stalla <alessiostalla at gmail.com> wrote:
>> >
>> > Greetings everyone,
>> >
>> > 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?
Just tested this for Allegro CL:
(eval-when (compile eval load) (require :osi))
(defun echo-off ()
(let ((tm (excl.osi:tcgetattr *terminal-io*)))
(setf (excl.osi:termios-lflag tm)
(logandc2 (excl.osi:termios-lflag tm) excl.osi:*echo*))
(excl.osi:tcsetattr *terminal-io* tm)))
(defun echo-on ()
(let ((tm (excl.osi:tcgetattr *terminal-io*)))
(setf (excl.osi:termios-lflag tm)
(logior (excl.osi:termios-lflag tm) excl.osi:*echo*))
(excl.osi:tcsetattr *terminal-io* tm)))
(defun prompt-for-value (prompt)
(format t "~&~a " prompt)
(force-output)
(read-line))
(defun prompt-for-value/no-echo (prompt)
(format t "~&~a " prompt)
(force-output)
(echo-off)
(unwind-protect
(read-line)
(echo-on)))
(defun get-passphrase-from-user ()
(prompt-for-value/no-echo "Passphrase?"))
More information about the pro
mailing list