l 3 usershadow: update passwd to behave correctly
This commit is contained in:
parent
ab684bf6d8
commit
2ea9b739ac
|
@ -70,9 +70,7 @@
|
||||||
extra-depends = deps;
|
extra-depends = deps;
|
||||||
text = ''
|
text = ''
|
||||||
import Data.Monoid
|
import Data.Monoid
|
||||||
import System.IO
|
import System.Environment (getArgs)
|
||||||
import Data.Char (chr)
|
|
||||||
import System.Environment (getEnv, getArgs)
|
|
||||||
import Crypto.PasswordStore (verifyPasswordWith, pbkdf2)
|
import Crypto.PasswordStore (verifyPasswordWith, pbkdf2)
|
||||||
import qualified Data.ByteString.Char8 as BS8
|
import qualified Data.ByteString.Char8 as BS8
|
||||||
import System.Exit (exitFailure, exitSuccess)
|
import System.Exit (exitFailure, exitSuccess)
|
||||||
|
@ -96,16 +94,29 @@
|
||||||
import System.Environment (getEnv)
|
import System.Environment (getEnv)
|
||||||
import Crypto.PasswordStore (makePasswordWith, pbkdf2)
|
import Crypto.PasswordStore (makePasswordWith, pbkdf2)
|
||||||
import qualified Data.ByteString.Char8 as BS8
|
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 :: IO ()
|
||||||
main = do
|
main = do
|
||||||
home <- getEnv "HOME"
|
home <- getEnv "HOME"
|
||||||
putStrLn "password:"
|
mb_password <- bracket_ (hSetEcho stdin False) (hSetEcho stdin True) $ do
|
||||||
hSetEcho stdin False
|
putStr "Enter new UNIX password: "
|
||||||
password <- BS8.hGetLine stdin
|
hFlush stdout
|
||||||
hash <- makePasswordWith pbkdf2 password 10
|
password <- BS8.hGetLine stdin
|
||||||
BS8.writeFile (home ++ "/.shadow") hash
|
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"
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue