SagaSaga
Bcrypt

Bcrypt

Types

Config

record Config {
  cost: Int
}

Configuration for hashing

BcryptError

type BcryptError =
  | InvalidCost Int
  | InvalidHash String
  | HashError String
  deriving (Show, Eq, Debug)

Why a hashing or verification operation failed.

Functions

hasher

fun hasher : Config

A hasher with the default cost (12)

with_cost

fun with_cost : Int -> Config -> Config

Set the cost (work factor). Must be between 4 and 31; a value outside that range produces Err (InvalidCost cost) when you call hash.

hash

fun hash : String -> Config -> Result String BcryptError

Hash a password, producing a $2b$ bcrypt string (salt embedded). Returns Err (InvalidCost cost) if the configured cost is out of range.

verify

fun verify : String -> String -> Result Bool BcryptError

Verify a password against a bcrypt hash. Ok True on match, Ok False on mismatch, and Err (InvalidHash msg) if the hash string is malformed.