From a615538d96028d19f72d58008b1a88dfce4b7d35 Mon Sep 17 00:00:00 2001 From: Jonathan Lamothe Date: Fri, 20 Mar 2020 20:20:59 -0400 Subject: [PATCH] confirm master password before creating new service --- ChangeLog.md | 1 + app/UI.hs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/ChangeLog.md b/ChangeLog.md index 8fbb5e7..f792cae 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -4,6 +4,7 @@ - refactoring - store the database where Windows can find it +- confirm master password before creating new service ## 0.2 diff --git a/app/UI.hs b/app/UI.hs index f1ab387..a05ff3d 100644 --- a/app/UI.hs +++ b/app/UI.hs @@ -20,6 +20,8 @@ License along with this program. If not, see -} +{-# LANGUAGE LambdaCase #-} + module UI (getMasterPass, mainMenu) where import Control.Lens (over, set, view, (^.)) @@ -37,6 +39,7 @@ import System.Console.HCL , reqPassword , reqResp , required + , runRequest ) import Password @@ -67,6 +70,20 @@ mainMenu = addPassword :: S.StateT Status IO () addPassword = do + pass <- S.gets (^.masterPass) + + lift (runRequest $ prompt "confirm master password: " reqPassword) + >>= \case + Nothing -> mainMenu + Just chkPass + | pass == chkPass -> addPassword' + + | otherwise -> do + lift $ putStrLn "Incorrect master password." + mainMenu + +addPassword' :: S.StateT Status IO () +addPassword' = do svc <- req $ prompt "service name: " reqResp ifServExists svc (do