applied hlint suggestions
This commit is contained in:
11
app/Main.hs
11
app/Main.hs
@@ -28,6 +28,7 @@ import Control.Lens (makeLenses, set, view)
|
|||||||
import qualified Control.Monad.Trans.State as S
|
import qualified Control.Monad.Trans.State as S
|
||||||
import Control.Monad (join)
|
import Control.Monad (join)
|
||||||
import Control.Monad.Trans.Class (lift)
|
import Control.Monad.Trans.Class (lift)
|
||||||
|
import Data.Foldable (mapM_)
|
||||||
import Data.Maybe (fromJust)
|
import Data.Maybe (fromJust)
|
||||||
import qualified System.Console.HCL as R
|
import qualified System.Console.HCL as R
|
||||||
|
|
||||||
@@ -38,11 +39,7 @@ data Status = Status
|
|||||||
makeLenses ''Status
|
makeLenses ''Status
|
||||||
|
|
||||||
main :: IO ()
|
main :: IO ()
|
||||||
main = do
|
main = R.runRequest setup >>= mapM_ (S.evalStateT mainMenu)
|
||||||
ms <- R.runRequest setup
|
|
||||||
case ms of
|
|
||||||
Nothing -> return ()
|
|
||||||
Just s -> S.evalStateT mainMenu s
|
|
||||||
|
|
||||||
setup :: R.Request Status
|
setup :: R.Request Status
|
||||||
setup = fmap Status getMasterPass
|
setup = fmap Status getMasterPass
|
||||||
@@ -58,7 +55,7 @@ getMasterPass = do
|
|||||||
else return p1
|
else return p1
|
||||||
|
|
||||||
mainMenu :: S.StateT Status IO ()
|
mainMenu :: S.StateT Status IO ()
|
||||||
mainMenu = do
|
mainMenu =
|
||||||
menu "Main Menu"
|
menu "Main Menu"
|
||||||
[ ( "change master password", changeMasterPass )
|
[ ( "change master password", changeMasterPass )
|
||||||
, ( "lock session", lockSession )
|
, ( "lock session", lockSession )
|
||||||
@@ -76,7 +73,7 @@ lockSession :: S.StateT Status IO ()
|
|||||||
lockSession = do
|
lockSession = do
|
||||||
lift $ putStrLn "\nsession locked"
|
lift $ putStrLn "\nsession locked"
|
||||||
pass <- S.gets $ view masterPass
|
pass <- S.gets $ view masterPass
|
||||||
mx <- lift $ R.runRequest $ R.prompt "password: " $ R.reqPassword
|
mx <- lift $ R.runRequest $ R.prompt "password: " R.reqPassword
|
||||||
case mx of
|
case mx of
|
||||||
Nothing -> lockSession
|
Nothing -> lockSession
|
||||||
Just x -> if x == pass
|
Just x -> if x == pass
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ validatePWPolicy
|
|||||||
-- ^ the policy being validated
|
-- ^ the policy being validated
|
||||||
-> Bool
|
-> Bool
|
||||||
-- ^ indicates whether or not the policy is valid
|
-- ^ indicates whether or not the policy is valid
|
||||||
validatePWPolicy x = all id
|
validatePWPolicy x = and
|
||||||
[ needed <= x^.pwLength
|
[ needed <= x^.pwLength
|
||||||
, x^.pwLength >= 0
|
, x^.pwLength >= 0
|
||||||
, x^.pwUpper >= 0
|
, x^.pwUpper >= 0
|
||||||
@@ -91,7 +91,7 @@ applyPWPolicy
|
|||||||
-- ^ the policy
|
-- ^ the policy
|
||||||
-> Bool
|
-> Bool
|
||||||
-- ^ @"True"@ if the password meets the policy, @"False"@ otherwise
|
-- ^ @"True"@ if the password meets the policy, @"False"@ otherwise
|
||||||
applyPWPolicy pw policy = all id
|
applyPWPolicy pw policy = and
|
||||||
[ length pw <= policy^.pwLength
|
[ length pw <= policy^.pwLength
|
||||||
, length (filter isUpper pw) >= policy^.pwUpper
|
, length (filter isUpper pw) >= policy^.pwUpper
|
||||||
, length (filter isLower pw) >= policy^.pwLower
|
, length (filter isLower pw) >= policy^.pwLower
|
||||||
|
|||||||
@@ -28,18 +28,18 @@ import Test.HUnit (Test(..), (~?=))
|
|||||||
import Password
|
import Password
|
||||||
|
|
||||||
tests = TestLabel "applyPWPolicy" $ TestList $ map test'
|
tests = TestLabel "applyPWPolicy" $ TestList $ map test'
|
||||||
[ ( "default pass", "password", id, True )
|
[ ( "default pass", "password", id, True )
|
||||||
, ( "too long", take 99 $ repeat 'x', id, False )
|
, ( "too long", replicate 99 'x', id, False )
|
||||||
, ( "insufficient upper", "password", set pwUpper 1, False )
|
, ( "insufficient upper", "password", set pwUpper 1, False )
|
||||||
, ( "sufficient upper", "Password", set pwUpper 1, True )
|
, ( "sufficient upper", "Password", set pwUpper 1, True )
|
||||||
, ( "insufficient lower", "PASSWORD", set pwLower 1, False )
|
, ( "insufficient lower", "PASSWORD", set pwLower 1, False )
|
||||||
, ( "sufficient lower", "password", set pwLower 1, True )
|
, ( "sufficient lower", "password", set pwLower 1, True )
|
||||||
, ( "insufficient digits", "password", set pwDigits 1, False )
|
, ( "insufficient digits", "password", set pwDigits 1, False )
|
||||||
, ( "sufficient digits", "password1", set pwDigits 1, True )
|
, ( "sufficient digits", "password1", set pwDigits 1, True )
|
||||||
, ( "insufficient special", "Password1", spec (Just 1), False )
|
, ( "insufficient special", "Password1", spec (Just 1), False )
|
||||||
, ( "sufficient special", "Password1/", spec (Just 1), True )
|
, ( "sufficient special", "Password1/", spec (Just 1), True )
|
||||||
, ( "illegal special", "Password1/", spec Nothing, False )
|
, ( "illegal special", "Password1/", spec Nothing, False )
|
||||||
, ( "bad policy", "password", badPolicy, False )
|
, ( "bad policy", "password", badPolicy, False )
|
||||||
]
|
]
|
||||||
|
|
||||||
test' (label, pw, f, expect) = TestLabel label $
|
test' (label, pw, f, expect) = TestLabel label $
|
||||||
|
|||||||
Reference in New Issue
Block a user