-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | plain-text password and hashed password datatypes and functions -- -- A library providing types for working with plain-text and hashed -- passwords, generally for web applications. @package password @version 1.0.0.0 -- | This module provides an easy way for interacting with passwords from -- Haskell. It provides the types Pass and PassHash, which -- correspond to plain-text and hashed passwords. -- -- It also provides functions for hashing (hashPass) and checking -- passwords (checkPass). -- -- The real benefit of this module is that there is a corresponding -- password-instances module that provides canonical typeclass -- instances for Pass and PassHash for many common -- typeclasses, like FromJSON from aeson, -- PersistField from persistent, etc. -- -- See the password-instances module for more information. module Data.Password -- | A plain-text password. -- -- This represents a plain-text password that has NOT been hashed. -- -- You should be careful with Pass. Make sure not to write it to -- logs or store it in a database. -- -- You can construct a Pass by using the mkPass function or -- as literal strings together with the OverloadedStrings pragma (or -- manually, by using fromString on a String). -- Alternatively, you could also use some of the instances in the -- password-instances library. data Pass -- | Construct a Pass mkPass :: Text -> Pass -- | A hashed password. -- -- This represents a password that has been put through a hashing -- function. The hashed password can be stored in a database. newtype PassHash PassHash :: Text -> PassHash [unPassHash] :: PassHash -> Text newtype Salt Salt :: ByteString -> Salt [getSalt] :: Salt -> ByteString -- | Just like hashPassWithSalt, but generate a new Salt -- everytime with a call to newSalt. -- --
--   >>> hashPass $ mkPass "foobar"
--   PassHash {unPassHash = "14|8|1|...|..."}
--   
hashPass :: MonadIO m => Pass -> m PassHash -- | Hash a password with the given Salt. -- -- The resulting PassHash has the parameters used to hash it, as -- well as the Salt appended to it, separated by |. -- -- The input Salt and resulting PassHash are both byte-64 -- encoded. -- --
--   >>> let salt = Salt "abcdefghijklmnopqrstuvwxyz012345"
--   
--   >>> hashPassWithSalt salt (mkPass "foobar")
--   PassHash {unPassHash = "14|8|1|YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXowMTIzNDU=|nENDaqWBmPKapAqQ3//H0iBImweGjoTqn5SvBS8Mc9FPFbzq6w65maYPZaO+SPamVZRXQjARQ8Y+5rhuDhjIhw=="}
--   
-- -- (Note that we use an explicit Salt in the example above. This -- is so that the example is reproducible, but in general you should use -- hashPass. hashPass generates a new Salt everytime -- it is called.) -- -- This function uses the hash function from the scrypt package: -- encryptPass. hashPassWithSalt :: Salt -> Pass -> PassHash -- | Generate a random 32-byte salt. newSalt :: MonadIO m => m Salt -- | Check a Pass against a PassHash. -- -- Returns PassCheckSuccess on success. -- --
--   >>> let salt = Salt "abcdefghijklmnopqrstuvwxyz012345"
--   
--   >>> let pass = mkPass "foobar"
--   
--   >>> let passHash = hashPassWithSalt salt pass
--   
--   >>> checkPass pass passHash
--   PassCheckSuccess
--   
-- -- Returns PassCheckFail If an incorrect Pass or -- PassHash is used. -- --
--   >>> let badpass = mkPass "incorrect-password"
--   
--   >>> checkPass badpass passHash
--   PassCheckFail
--   
-- -- This should always fail if an incorrect password is given. -- --
--   \(Blind badpass) -> let correctPassHash = hashPassWithSalt salt "foobar" in checkPass badpass correctPassHash == PassCheckFail
--   
checkPass :: Pass -> PassHash -> PassCheck -- | The result of a checking a password against a hashed version. This is -- returned by checkPass. data PassCheck -- | The password check was successful. The plain-text password matches the -- hashed password. PassCheckSuccess :: PassCheck -- | The password check failed. The plain-text password does not match the -- hashed password. PassCheckFail :: PassCheck -- | This is an unsafe function that shows a password in plain-text. -- --
--   >>> unsafeShowPasswordText $ mkPass "foobar"
--   "foobar"
--   
-- -- You should generally not use this function. unsafeShowPassword :: Pass -> String -- | This is like unsafeShowPassword but produces a Text -- instead of a String. unsafeShowPasswordText :: Pass -> Text instance GHC.Show.Show Data.Password.PassCheck instance GHC.Read.Read Data.Password.PassCheck instance GHC.Classes.Eq Data.Password.PassCheck instance GHC.Show.Show Data.Password.PassHash instance GHC.Read.Read Data.Password.PassHash instance GHC.Classes.Ord Data.Password.PassHash instance GHC.Classes.Eq Data.Password.PassHash instance Data.String.IsString Data.Password.Pass instance GHC.Show.Show Data.Password.Pass