From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id RAA18291; Sat, 7 Feb 2004 17:31:32 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA22110 for ; Sat, 7 Feb 2004 17:31:30 +0100 (MET) Received: from mail.davidb.org (adsl-64-172-240-129.dsl.sndg02.pacbell.net [64.172.240.129]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id i17GVTv05306 for ; Sat, 7 Feb 2004 17:31:29 +0100 (MET) Received: from davidb by mail.davidb.org with local (Exim 3.36 #1 (Debian)) id 1ApVMU-0005He-00; Sat, 07 Feb 2004 08:31:18 -0800 Date: Sat, 7 Feb 2004 08:31:18 -0800 From: David Brown To: David MENTRE Cc: Alain.Frisch@ens.fr, caml-list@inria.fr Subject: Re: [Caml-list] How to read a password without displaying it? Message-ID: <20040207163118.GA20250@davidb.org> References: <874qu2sz3y.fsf@linux-france.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874qu2sz3y.fsf@linux-france.org> User-Agent: Mutt/1.5.4i X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 caml-list:01 2004:99 tcgetattr:01 stdin:01 tcsetattr:01 stdin:01 tcsetattr:01 tcsaflush:01 mentre:01 exception:02 unix:02 dave:03 wrote:03 let:04 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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