added PWDatabase and PWData

This commit is contained in:
Jonathan Lamothe 2018-12-17 15:18:01 -05:00
parent 2b9bedced5
commit 3923ea1ef3
2 changed files with 20 additions and 1 deletions

View File

@ -21,6 +21,8 @@ description: Please see the README on GitHub at <https://github.com/jlam
dependencies: dependencies:
- base >= 4.7 && < 5 - base >= 4.7 && < 5
- bytestring
- containers
- lens - lens
library: library:

View File

@ -26,9 +26,12 @@ License along with this program. If not, see
module Password ( module Password (
-- * Data Types -- * Data Types
PWPolicy (..), PWDatabase, PWData(..), PWPolicy (..),
-- ** Lenses -- ** Lenses
-- $lenses -- $lenses
-- *** PWData
pwPolicy, pwSalt,
-- *** PWPolicy
pwLength, pwUpper, pwLower, pwDigits, pwSpecial, pwLength, pwUpper, pwLower, pwDigits, pwSpecial,
-- ** Default Instances -- ** Default Instances
newPWPolicy, newPWPolicy,
@ -38,8 +41,21 @@ module Password (
import Control.Lens (makeLenses, (^.)) import Control.Lens (makeLenses, (^.))
import Data.Char (isUpper, isLower, isDigit, isAlphaNum) import Data.Char (isUpper, isLower, isDigit, isAlphaNum)
import qualified Data.ByteString as B
import qualified Data.Map as M
import Data.Maybe (fromMaybe) import Data.Maybe (fromMaybe)
-- | a mapping of service names to password data
type PWDatabase = M.Map String PWData
-- | data necessary to construct a password
data PWData = PWData
{ _pwPolicy :: PWPolicy
-- ^ the password policy
, _pwSalt :: B.ByteString
-- ^ random data used to generate the password
} deriving (Eq, Show)
-- | defines a password policy -- | defines a password policy
data PWPolicy = PWPolicy data PWPolicy = PWPolicy
{ _pwLength :: Int { _pwLength :: Int
@ -61,6 +77,7 @@ data PWPolicy = PWPolicy
-- details. -- details.
makeLenses ''PWPolicy makeLenses ''PWPolicy
makeLenses ''PWData
-- | default password policy -- | default password policy
newPWPolicy :: PWPolicy newPWPolicy :: PWPolicy