Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] How to read a password without displaying it?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Brown <caml-list@d...>
Subject: Re: [Caml-list] How to read a password without displaying it?
On Sat, Feb 07, 2004 at 04:12:01PM +0100, David MENTRE wrote:

> open Unix
> [...]
> let read_password () =
>   let term_init = tcgetattr stdin in
>   let term_no_echo = { term_init with c_echo = false; } in
>   tcsetattr stdin TCSANOW term_no_echo;
>   let password = read_line () in
>   tcsetattr stdin TCSAFLUSH term_init;
>   password

The only suggestion would be to put the read_line in a try clause, and
restore the terminal settings if an exception is raised.  Otherwise,
pressing ^C leaves the terminal with echo off.

Dave

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners