Module Passe.Bcrypt

The bcrypt hashing algorithm.

type error = [
  1. | `Hash_failure
  2. | `Invalid_cost of string
  3. | `Invalid_hash of string
  4. | `Invalid_prefix of string
  5. | `Invalid_salt_length of int
  6. | `Salt_generation_failure
  7. | `Truncated of int
]

Errors that can occur during hashing and verification.

val pp_error : Stdlib.Format.formatter -> error -> unit
val hash_with_salt : salt:string -> string -> (Passe__.Hash.t, error) Stdlib.result

hash_with_salt ~salt s hash s password with the given salt and params.

val hash_with_salt_exn : salt:string -> string -> Passe__.Hash.t

hash_with_salt_exn ~salt ~params s is the same as hash_with_salt ~salt ~params s but raises Invalid_argument s on error.

val hash : ?cost:int -> string -> (Passe__.Hash.t, error) Stdlib.result

hash ?cost s hash s password with a randomly generated salt and the given cost (or default cost if not provided).

val hash_exn : ?cost:int -> string -> Passe__.Hash.t

hash_exn ?cost s is the same as hash ?cost s but raises Invalid_argument s on error.

val verify : hash:Passe__.Hash.t -> string -> (bool, error) Stdlib.result

verify ~hash s verifies that s matches the given hash.

val verify_exn : hash:Passe__.Hash.t -> string -> bool

verify_exn ~hash s is the same as verify ~hash s but raises Invalid_argument s on error.