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 MENTRE <dmentre@l...>
Subject: Re: [Caml-list] How to read a password without displaying it?
Hello Alain,

Alain.Frisch@ens.fr writes:

> The field c_echo in the record type Unix.terminal_io might be the
> solution.

Thanks a lot Alain, you found the right solution.

Here is the working code:

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


Many thanks,
d.
-- 
 David Mentré <dmentre@linux-france.org>

-------------------
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