diff options
author | makefu <github@syntax-fehler.de> | 2016-11-27 15:24:22 +0100 |
---|---|---|
committer | makefu <github@syntax-fehler.de> | 2016-11-27 15:24:22 +0100 |
commit | b94fc3265b92f70ecb4507484e378e8f8084477c (patch) | |
tree | e9acdb99cafdd1362bb98a8f00139dde6edef6a4 /lass/3modules/usershadow.nix | |
parent | bcc2b327c4dbd34162db8cf81fbbc7688feafd9a (diff) | |
parent | da3022389d1da7ac9c2ca42eb2d16582b96e0074 (diff) |
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'lass/3modules/usershadow.nix')
-rw-r--r-- | lass/3modules/usershadow.nix | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/lass/3modules/usershadow.nix b/lass/3modules/usershadow.nix index a8ab1c52a..c0be053ab 100644 --- a/lass/3modules/usershadow.nix +++ b/lass/3modules/usershadow.nix @@ -70,9 +70,7 @@ extra-depends = deps; text = '' import Data.Monoid - import System.IO - import Data.Char (chr) - import System.Environment (getEnv, getArgs) + import System.Environment (getArgs) import Crypto.PasswordStore (verifyPasswordWith, pbkdf2) import qualified Data.ByteString.Char8 as BS8 import System.Exit (exitFailure, exitSuccess) @@ -96,16 +94,29 @@ import System.Environment (getEnv) import Crypto.PasswordStore (makePasswordWith, pbkdf2) import qualified Data.ByteString.Char8 as BS8 - import System.IO (stdin, hSetEcho, putStrLn) + import System.IO (stdin, stdout, hSetEcho, hFlush, putStr, putStrLn) + import Control.Exception (bracket_) main :: IO () main = do home <- getEnv "HOME" - putStrLn "password:" - hSetEcho stdin False - password <- BS8.hGetLine stdin - hash <- makePasswordWith pbkdf2 password 10 - BS8.writeFile (home ++ "/.shadow") hash + mb_password <- bracket_ (hSetEcho stdin False) (hSetEcho stdin True) $ do + putStr "Enter new UNIX password: " + hFlush stdout + password <- BS8.hGetLine stdin + putStrLn "" + putStr "Retype new UNIX password: " + hFlush stdout + password2 <- BS8.hGetLine stdin + return $ if password == password2 + then Just password + else Nothing + case mb_password of + Just password -> do + hash <- makePasswordWith pbkdf2 password 10 + BS8.writeFile (home ++ "/.shadow") hash + putStrLn "passwd: all authentication tokens updated successfully." + Nothing -> putStrLn "Sorry, passwords do not match" ''; }; }; |