Disable echo in POSIX terminal

Hello all, I've written a little Haskell program to get information from a MySQL database (great thanks to anybody reading this who works on HSQL, by the way) but I want to keep the user's password concealed, obviously. Currently I prompt for it from the terminal, but the problem is that it's echoed just like all other input. I would like to disable input echo when asking for the password, but I'm not sure how. I notice there's a System.POSIX.Terminal module, but I have no idea how to use it, or whether it will do what I want. Any ideas would be greatly appreciated. Best regards. -- Taylor Venable taylor@metasyntax.net http://real.metasyntax.net:2357/

Hi
I've written a little Haskell program to get information from a MySQL database (great thanks to anybody reading this who works on HSQL, by the way) but I want to keep the user's password concealed, obviously. Currently I prompt for it from the terminal, but the problem is that it's echoed just like all other input. I would like to disable input echo when asking for the password, but I'm not sure how. I notice there's a System.POSIX.Terminal module, but I have no idea how to use it, or whether it will do what I want. Any ideas would be greatly appreciated.
http://haskell.org/hoogle/?q=echo A quick Hoogle search for echo suggests hSetEcho, so perhaps hSetEcho stdin False would work. Thanks Neil

On Fri, 9 Nov 2007 16:09:57 +0000
"Neil Mitchell"
Hi
I've written a little Haskell program to get information from a MySQL database (great thanks to anybody reading this who works on HSQL, by the way) but I want to keep the user's password concealed, obviously. Currently I prompt for it from the terminal, but the problem is that it's echoed just like all other input. I would like to disable input echo when asking for the password, but I'm not sure how. I notice there's a System.POSIX.Terminal module, but I have no idea how to use it, or whether it will do what I want. Any ideas would be greatly appreciated.
http://haskell.org/hoogle/?q=echo
A quick Hoogle search for echo suggests hSetEcho, so perhaps hSetEcho stdin False would work.
Oh my, I completely forgot about Hoogle and missed those obvious functions. That's it exactly. Thanks very much for the pointers! -- Taylor Venable taylor@metasyntax.net http://real.metasyntax.net:2357/

I never used System.POSIX.Terminal myself but from what I read in the
haddock documentation I think this function can help you.
import System.Posix.Types (Fd)
import System.Posix.Terminal
disableEcho :: Fd -> IO ()
disableEcho fd = do
attribs <- getTerminalAttributes fd
setTerminalAttributes fd (withoutMode attribs EnableEcho) Immediately
On Nov 9, 2007 4:59 PM, Taylor Venable
Hello all,
I've written a little Haskell program to get information from a MySQL database (great thanks to anybody reading this who works on HSQL, by the way) but I want to keep the user's password concealed, obviously. Currently I prompt for it from the terminal, but the problem is that it's echoed just like all other input. I would like to disable input echo when asking for the password, but I'm not sure how. I notice there's a System.POSIX.Terminal module, but I have no idea how to use it, or whether it will do what I want. Any ideas would be greatly appreciated.
Best regards.
-- Taylor Venable taylor@metasyntax.net http://real.metasyntax.net:2357/ _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Fri, 2007-11-09 at 10:59 -0500, Taylor Venable wrote:
Hello all,
I've written a little Haskell program to get information from a MySQL database (great thanks to anybody reading this who works on HSQL, by the way) but I want to keep the user's password concealed, obviously. Currently I prompt for it from the terminal, but the problem is that it's echoed just like all other input. I would like to disable input echo when asking for the password, but I'm not sure how. I notice there's a System.POSIX.Terminal module, but I have no idea how to use it, or whether it will do what I want. Any ideas would be greatly appreciated.
Best regards.
In C you usually use: getpasswd (http://docsrv.sco.com:507/en/man/html.S/getpasswd.S.html) I cannot find it System.Posix, so you might have to write your own FFI bindings. Otherwise, you can play around with the terminal modes from: http://haskell.org/ghc/docs/latest/html/libraries/unix-2.2.0.0/System-Posix-... Good luck!

I this there's no need for a binding
How about this?
import Control.Monad (when)
import System.IO
getpasswd :: Handle -> IO String
getpasswd h = do wasEnabled <- hGetEcho h
when wasEnabled (hSetEcho h False)
str <- hGetLine h
when wasEnabled (hSetEcho h True)
return str
On Nov 9, 2007 5:20 PM, Thomas Schilling
On Fri, 2007-11-09 at 10:59 -0500, Taylor Venable wrote:
Hello all,
I've written a little Haskell program to get information from a MySQL database (great thanks to anybody reading this who works on HSQL, by the way) but I want to keep the user's password concealed, obviously. Currently I prompt for it from the terminal, but the problem is that it's echoed just like all other input. I would like to disable input echo when asking for the password, but I'm not sure how. I notice there's a System.POSIX.Terminal module, but I have no idea how to use it, or whether it will do what I want. Any ideas would be greatly appreciated.
Best regards.
In C you usually use: getpasswd (http://docsrv.sco.com:507/en/man/html.S/getpasswd.S.html)
I cannot find it System.Posix, so you might have to write your own FFI bindings. Otherwise, you can play around with the terminal modes from:
http://haskell.org/ghc/docs/latest/html/libraries/unix-2.2.0.0/System-Posix-...
Good luck!
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

On Fri, 2007-11-09 at 17:41 +0100, Alfonso Acosta wrote:
I this there's no need for a binding
How about this?
import Control.Monad (when) import System.IO
getpasswd :: Handle -> IO String getpasswd h = do wasEnabled <- hGetEcho h when wasEnabled (hSetEcho h False) str <- hGetLine h when wasEnabled (hSetEcho h True) return str
Pointless frobbing but is there any issue with setting the echo to False when it is already False? Otherwise not checking seems to both simpler and quicker (not that performance matters), i.e. getpasswd h = do wasEnabled <- hGetEcho h hSetEcho h False str <- hGetLine h hSetEcho wasEnabled return str

On Fri, 9 Nov 2007, Derek Elkins wrote:
Pointless frobbing but is there any issue with setting the echo to False when it is already False? Otherwise not checking seems to both simpler and quicker (not that performance matters), i.e. getpasswd h = do wasEnabled <- hGetEcho h hSetEcho h False str <- hGetLine h hSetEcho wasEnabled return str
Should one enclose this in 'bracket'?
participants (6)
-
Alfonso Acosta
-
Derek Elkins
-
Henning Thielemann
-
Neil Mitchell
-
Taylor Venable
-
Thomas Schilling