Created
May 15, 2013 09:15
-
-
Save kazu-yamamoto/5582673 to your computer and use it in GitHub Desktop.
Reading a password in Haskell
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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