Prompting for a password in Haskell command line application

前端 未结 6 1070
傲寒
傲寒 2021-02-01 04:10

The following Haskell program prompts the user for a password in the terminal and continues if he has entered the correct one:

main = do
    putStrLn \"Password:         


        
6条回答
  •  忘掉有多难
    2021-02-01 04:19

    I have found this useful when reading passwords:

    import Control.Exception
    import System.IO
    
    withoutEcho :: IO a -> IO a
    withoutEcho action =
      finally (hSetEcho stdin False >> action) (hSetEcho stdin True)
    

提交回复
热议问题