English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

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: 2004-02-07 (15:12)
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;

Many thanks,
 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