Force User fields to be correct

This commit is contained in:
Gregor Kleen 2018-07-04 12:27:08 +02:00
parent b48efb1035
commit efe7546a24

View File

@ -209,8 +209,9 @@ addPWEntry :: FilePath {-^ Password file -}
-> User
-> Text {-^ Password -}
-> IO ()
addPWEntry pwFile pwUser' (Text.encodeUtf8 -> pw) = do
addPWEntry pwFile User{..} (Text.encodeUtf8 -> pw) = do
(Text.decodeUtf8 -> pwHash) <- makePassword pw 14
let pwEntry = PWEntry{ pwUser = pwUser', .. }
let pwEntry = PWEntry{ pwUser = User{ userPlugin = "PWFile", .. }, .. }
newUser = userIdent
c <- either (const []) id <$> Yaml.decodeFileEither pwFile
Yaml.encodeFile pwFile $ pwEntry : [ c' | c' <- c, ((/=) `on` (userIdent . pwUser)) c' pwEntry ]
Yaml.encodeFile pwFile $ pwEntry : [ c' | c'@(PWEntry{pwUser=User{..}}) <- c, userIdent /= newUser ]