• How can I input a password in Chez Scheme?

    From Phil Bewig@21:1/5 to All on Mon Oct 28 09:07:38 2019
    I want to write a simple file encryption/decryption program in Chez Scheme, using the scripting feature of Chez Scheme to run the program from the Unix command line. To do that, I need to input the key. I want to prompt the user to enter the key at the
    keyboard, but with the asterisks echoed to the screen instead of the letters of the key. In other words, an interaction with the program should look like:

    $ crypt <infile >outfile
    Enter key: ***********
    Repeat key: ***********

    How can I get the terminal into raw mode so it doesn't echo the key as it is typed?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Brad Lucier@21:1/5 to Phil Bewig on Tue Oct 29 14:42:53 2019
    On Monday, October 28, 2019 at 12:07:42 PM UTC-4, Phil Bewig wrote:
    I want to write a simple file encryption/decryption program in Chez Scheme, using the scripting feature of Chez Scheme to run the program from the Unix command line. To do that, I need to input the key. I want to prompt the user to enter the key at the
    keyboard, but with the asterisks echoed to the screen instead of the letters of the key. In other words, an interaction with the program should look like:

    $ crypt <infile >outfile
    Enter key: ***********
    Repeat key: ***********

    How can I get the terminal into raw mode so it doesn't echo the key as it is typed?

    I asked Marc Feeley how he'd do it in Gambit, and he came up with the following. HTH. Brad

    (define tty ##console-port)

    (define (raw-mode)
    (tty-mode-set! tty
    #f ;; input-allow-special
    #f ;; input-echo
    #t ;; input-raw
    #t ;; output-raw
    0)) ;; speed

    (define (cooked-mode)
    (tty-mode-set! tty
    #t ;; input-allow-special
    #t ;; input-echo
    #f ;; input-raw
    #f ;; output-raw
    0)) ;; speed

    (define (read-password)
    (raw-mode)
    (let loop ((chars '()))
    (let ((c (read-char tty)))
    (cond ((or (eof-object? c)
    (char=? c #\return)
    (char=? c #\newline))
    (cooked-mode)
    (display "\n" tty)
    (list->string (reverse chars)))
    ((or (char=? c #\backspace)
    (char=? c #\delete))
    (if (pair? chars)
    (begin
    (display "\b \b" tty)
    (loop (cdr chars)))
    (loop chars)))
    (else
    (display "*" tty)
    (loop (cons c chars)))))))

    (display "username: ")

    (let ((username (read-line tty)))

    (display "password: ")

    (let ((password (read-password)))
    (pretty-print (list 'username= username
    'password= password)
    tty)))

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)