Documentation
    Preparing search index...

    Hash driver built on top of "bcrypt" hash algorigthm. Under the hood we make use of the "bcrypt" npm package.

    The Bcrypt implementation uses the PHC formatting for creating and verifying hashes.

    const bcrypt = new Bcrypt({})

    await bcrypt.make('secret')
    // $bcrypt$v=98$r=10$Jtxi46WJ26OQ0khsYLLlnw$knXGfuRFsSjXdj88JydPOnUIglvm1S8

    Implements

    Index

    Constructors

    Methods

    • Check if the value is a valid hash. This method just checks for the formatting of the hash.

      bcrypt.isValidHash('hello world') // false
      bcrypt.isValidHash('$bcrypt$v=98$r=10$Jtxi46WJ26OQ0khsYLLlnw$knXGfuRFsSjXdj88JydPOnUIglvm1S8')

      Parameters

      • value: string

        The value to check

      Returns boolean

      True if the value is a valid Bcrypt hash format

    • Hash a plain text value

      const hash = await bcrypt.make('password')
      

      Parameters

      • value: string

        The plain text value to hash

      Returns Promise<string>

      Promise resolving to the Bcrypt hash

    • Verify the plain text value against an existing hash

      if (await bcrypt.verify(hash, plainText)) {

      }

      Parameters

      • hashedValue: string

        The hashed value to verify against

      • plainValue: string

        The plain text value to verify

      Returns Promise<boolean>

      Promise resolving to true if verification succeeds

    • Find if the hash value needs a rehash or not. The rehash is required when.

      1. The bcrypt version is changed
      2. Number of rounds are changed
      3. Bcrypt hash is not using MCF hash format
      4. The provided hash has not been hashed with bcrypt
      const isValid = await bcrypt.verify(hash, plainText)

      // Plain password is valid and hash needs a rehash
      if (isValid && await bcrypt.needsReHash(hash)) {
      const newHash = await bcrypt.make(plainText)
      }

      Parameters

      • value: string

        The hashed value to check

      Returns boolean

      True if the hash needs to be rehashed