Skip to content

Instantly share code, notes, and snippets.

@kazu-yamamoto
Created May 15, 2013 09:15
Show Gist options
  • Save kazu-yamamoto/5582673 to your computer and use it in GitHub Desktop.
Save kazu-yamamoto/5582673 to your computer and use it in GitHub Desktop.
Reading a password in Haskell
import System.Posix.IO
import System.Posix.Terminal
readPassword :: IO String
readPassword = do
echoOn <- getTerminalAttributes stdInput
let echoOff = withoutMode echoOn EnableEcho
fdWrite stdOutput "Password: "
setTerminalAttributes stdInput echoOff Immediately
pass <- getLine
setTerminalAttributes stdInput echoOn Immediately
fdWrite stdOutput "\n"
return pass
main :: IO ()
main = readPassword >>= print
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment