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:
- base >= 4.7 && < 5
- bytestring
- containers
- lens
library:

View File

@ -26,9 +26,12 @@ License along with this program. If not, see
module Password (
-- * Data Types
PWPolicy (..),
PWDatabase, PWData(..), PWPolicy (..),
-- ** Lenses
-- $lenses
-- *** PWData
pwPolicy, pwSalt,
-- *** PWPolicy
pwLength, pwUpper, pwLower, pwDigits, pwSpecial,
-- ** Default Instances
newPWPolicy,
@ -38,8 +41,21 @@ module Password (
import Control.Lens (makeLenses, (^.))
import Data.Char (isUpper, isLower, isDigit, isAlphaNum)
import qualified Data.ByteString as B
import qualified Data.Map as M
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
data PWPolicy = PWPolicy
{ _pwLength :: Int
@ -61,6 +77,7 @@ data PWPolicy = PWPolicy
-- details.
makeLenses ''PWPolicy
makeLenses ''PWData
-- | default password policy
newPWPolicy :: PWPolicy