caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] How to read a password without displaying it?
@ 2004-02-07 12:53 David MENTRE
  2004-02-07 13:17 ` Basile STARYNKEVITCH
  2004-02-07 14:50 ` Alain.Frisch
  0 siblings, 2 replies; 9+ messages in thread
From: David MENTRE @ 2004-02-07 12:53 UTC (permalink / raw)
  To: caml-list

Hello,

In my textual OCaml program, I would like to read a password. Currently,
I'm using read_line which is not very satisfying as the password is
display on screen.

  let passwd = read_line () in

Any idea how I might read the password without displaying it? 

I tried the following function, using input_char, but the password is
still displayed on screen:

let read_password () =
  let password_chars = ref [] in
  let loop = ref true in
  while !loop do
    let c = input_char stdin in
    if c <> '\n' then (
      password_chars := c :: !password_chars
     ) else (
      loop := false
     )
  done;
  let password = String.create (List.length !password_chars) in
  let _, res = List.fold_right (fun c (i, s) -> s.[i] <- c; (i+1, s))
      !password_chars (0, password) in
  res


Many thanks in advance for any help,
Yours,
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


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2004-02-07 16:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-02-07 12:53 [Caml-list] How to read a password without displaying it? David MENTRE
2004-02-07 13:17 ` Basile STARYNKEVITCH
2004-02-07 13:42   ` Maxence Guesdon
2004-02-07 14:45   ` David MENTRE
2004-02-07 14:54     ` David MENTRE
2004-02-07 14:59     ` Remi Vanicat
2004-02-07 14:50 ` Alain.Frisch
2004-02-07 15:12   ` David MENTRE
2004-02-07 16:31     ` David Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).