allow user to specify temporary alternate master password

This commit is contained in:
Jonathan Lamothe 2021-05-14 13:46:52 -04:00
parent 258ebf29fe
commit 6585d63385
2 changed files with 25 additions and 14 deletions

View File

@ -3,6 +3,7 @@
## current ## current
- set maximum version of transformers package - set maximum version of transformers package
- allow user to specifiy a temporary master password to retrieve a password
## 0.3.0.2 ## 0.3.0.2

View File

@ -27,7 +27,7 @@ module UI (getMasterPass, mainMenu) where
import Control.Monad (when) import Control.Monad (when)
import Control.Monad.Trans.Class (lift) import Control.Monad.Trans.Class (lift)
import qualified Control.Monad.Trans.State as S import qualified Control.Monad.Trans.State as S
import Lens.Micro (over, set, (^.)) import Lens.Micro (over, set, (^.), (.~))
import Lens.Micro.Extras (view) import Lens.Micro.Extras (view)
import System.Console.HCL import System.Console.HCL
( Request ( Request
@ -162,6 +162,7 @@ selectServ xs = menu "Select Service" $
servMenu :: String -> S.StateT Status IO () servMenu :: String -> S.StateT Status IO ()
servMenu x = menu x servMenu x = menu x
[ ( "show password", showPass x >> servMenu x ) [ ( "show password", showPass x >> servMenu x )
, ( "show alternate password", showAltPass x )
, ( "edit password", editPassMenu x ) , ( "edit password", editPassMenu x )
, ( "remove service", removeServ x ) , ( "remove service", removeServ x )
, ( "rename service", renameServ x ) , ( "rename service", renameServ x )
@ -225,16 +226,25 @@ doEditPolicy x = withService x mainMenu $ \d -> do
editPassMenu x editPassMenu x
showPass :: String -> S.StateT Status IO () showPass :: String -> S.StateT Status IO ()
showPass x = do showPass x = withService x
lift $ putStrLn ""
withService x
(lift $ putStrLn "The service could not be found in the database.") $ (lift $ putStrLn "The service could not be found in the database.") $
\d -> do \d -> do
lift $ putStrLn ""
mp <- S.gets $ view masterPass mp <- S.gets $ view masterPass
lift $ putStrLn $ case pwGenerate mp d of lift $ putStrLn $ case pwGenerate mp d of
Nothing -> "The password data were not valid." Nothing -> "The password data were not valid."
Just pw -> "password for " ++ x ++ ": " ++ pw Just pw -> "password for " ++ x ++ ": " ++ pw
showAltPass :: String -> S.StateT Status IO ()
showAltPass srv = do
lift $ putStrLn ""
old <- S.gets $ view masterPass
Just new <- lift $ runRequest $ required $ prompt "alternate master password: " reqPassword
S.modify $ masterPass .~ new
showPass srv
S.modify $ masterPass .~ old
servMenu srv
-- TODO: refactor this monstrosity -- TODO: refactor this monstrosity
editPolicy :: PWPolicy -> Request PWPolicy editPolicy :: PWPolicy -> Request PWPolicy
editPolicy policy = do editPolicy policy = do