caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: David MENTRE <dmentre@linux-france.org>
To: caml-list@inria.fr
Subject: [Caml-list] How to read a password without displaying it?
Date: Sat, 07 Feb 2004 13:53:20 +0100	[thread overview]
Message-ID: <87u123rqyn.fsf@linux-france.org> (raw)

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


             reply	other threads:[~2004-02-07 12:53 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-07 12:53 David MENTRE [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87u123rqyn.fsf@linux-france.org \
    --to=dmentre@linux-france.org \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).