esqueleto-pgcrypto-0.1.0.0: Esqueleto support for the pgcrypto PostgreSQL module
Safe HaskellNone
LanguageHaskell2010

Database.Esqueleto.PostgreSQL.Pgcrypto

Description

This module contains functions specific to the pgcrypto module

Synopsis

Documentation

data HashAlgorithm Source #

pgcrypto hashing algorithms see: https://www.postgresql.org/docs/current/pgcrypto.html

bf and xdes algorithms have an optional iterations count parameter. All limitations and considerations mentioned in the pgcrypto module documentation regarding iteration count apply. It is possible to supply an invalid iteration count, which will lead to an sql error.

Requires the pgcrypto module.

Constructors

BF (Maybe Word) 
MD5 
XDES (Maybe Word) 
DES 

toCrypt :: SqlString s => HashAlgorithm -> s -> SqlExpr (Value s) Source #

(crypt()) Calculate a crypt-like hash from the provided password

Requires the pgcrypto module.

WARNING: Using toCrypt may leak sensitive data via logging. Filtering logs in production environments when using toCrypt, such as using filterLogger on `monad-logger` based stacks is highly advised.

example:

share
    [mkPersist sqlSettings]
    [persistLowerCase|
    UserAccount json
        name T.Text
        UniqueName name
        passwordHash T.Text
        deriving Show Read Eq

insertSelect $ do
    pure $
        UserAccount
            <# val "username"
            & toCrypt (BF Nothing) "1234password"

fromCrypt :: SqlString s => SqlExpr (Value s) -> s -> SqlExpr (Value Bool) Source #

(crypt()) Retrieve a hashed password

Requires the pgcrypto module.

example:

share
    [mkPersist sqlSettings]
    [persistLowerCase|
    UserAccount json
        name T.Text
        UniqueName name
        passwordHash T.Text
        deriving Show Read Eq


login name pwd = select $ do
    user <- from $ Table UserAccount
    where_ $ user ^. UserAccountName ==. val name
        &&. fromCrypt (user ^. UserAccountPasswordHash) pwd
    pure user