Documentation
    Preparing search index...

    Hash driver built on top of "scrypt" hash algorigthm. Under the hood we make use of the Node.js crypto module

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

    const scrypt = new Scrypt({})

    await scrypt.make('secret')
    // $scrypt$n=16384,r=8,p=1$iILKD1gVSx6bqualYqyLBQ$DNzIISdmTQS6sFdQ1tJ3UCZ7Uun4uGHNjj0x8FHOqB0pf2LYsu9Xaj5MFhHg21qBz8l5q/oxpeV+ZkgTAj+OzQ

    Implements

    Index

    Constructors

    Methods

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

      scrypt.isValidHash('hello world') // false
      scrypt.isValidHash('$scrypt$n=16384,r=8,p=1$iILKD1gVSx6bqualYqyLBQ$DNzIISdmTQS6sFdQ1tJ3UCZ7Uun4uGHNjj0x8FHOqB0pf2LYsu9Xaj5MFhHg21qBz8l5q/oxpeV+ZkgTAj+OzQ')

      Parameters

      • value: string

        The value to check

      Returns boolean

      True if the value is a valid Scrypt hash format

    • Hash a plain text value

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

      Parameters

      • value: string

        The plain text value to hash

      Returns Promise<string>

      Promise resolving to the Scrypt hash

    • Verify the plain text value against an existing hash

      if (await scrypt.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 cost value is changed
      2. The blockSize value is changed
      3. The parallelization value is changed
      4. The provided hash has not been hashed with scrypt
      const isValid = await scrypt.verify(hash, plainText)

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

      Parameters

      • value: string

        The hashed value to check

      Returns boolean

      True if the hash needs to be rehashed