Context for credential-transformer procedures.

Hierarchy

Properties

comparablePassword: null | string

Optional password transformation settings, encoded in another password string. Settings could include algorithm settings, salt, etc.

Returns

password transformation settings

json: Json

Get the JSON helper for serializing/de-serializing JavaScript and Java types.

providedPassword: string

Returns

The password provided from the user to be transformed

request: ScriptRequest

The original request object. This can be used to access headers and parameters passed in the original request.

response: ScriptResponse

The Response object. Can be used to modify cookies in the response.

Methods

  • If a current hash of the password exists, this function should be used to compare the hash with the current password. If they match, then the already hashed password should be used as transformation result:

    ```
    if (comparablePassword !== null && context.bcryptCheckPassword(providedPassword, comparablePassword)) {
    return comparablePassword;
    } else {
    // Use context.bcryptHashPassword to generate a new hash.

    } ```

    Returns

    true if the passwords match. Always false if comparablePassword is null.

    Parameters

    • password: string

      The provided password

    • comparablePassword: null | string

      The previously stored password to compare with

    Returns boolean

  • Hash a password using BCrypt. This should be used for new hashes when creating the password hash the first time.

    Returns

    A string with the hashed password

    Parameters

    • password: string

      The password to hash

    • salt: string

      The salt using the BCrypt salting

    Returns string

  • Returns

    a random salt of the given length.

    Parameters

    • length: number

    Returns string

  • Returns

    a random salt for a BCrypt hash, with the given cost.

    Parameters

    • cost: number

      the the log2 of the number of rounds of hashing to apply - the work factor therefore increases as 2^log_rounds.

    Returns string

  • Returns

    a random salt for a BCrypt hash.

    Returns string

  • Returns

    a random salt for a Sha2With256 hash, with the given number of rounds.

    Parameters

    • rounds: number

    Returns string

  • Returns

    a random salt for a Sha2With512 hash, with the given number of rounds.

    Parameters

    • rounds: number

    Returns string

  • Optional password transformation settings, encoded in another password string. Settings could include algorithm settings, salt, etc.

    Returns

    password transformation settings

    Returns null | string

  • Returns

    The password provided from the user to be transformed

    Returns string

  • Check if a password matches the hashed password. If they match, the transformation can return the already hashed password.

    ```
    if (comparablePassword !== null && context.phpassCheckPassword(providedPassword, comparablePassword)) {
    return comparablePassword;
    } else {
    // Use context.phpassHashPassword to generate a new hash.
    }
    ```

    Returns

    true if passwords match. Always false if comparablePassword is null.

    Parameters

    • password: string

      The provided password

    • comparablePassword: null | string

      The stored password hash

    Returns boolean

  • Hash a password using Phpass.

    Returns

    A string with the hashed password

    Parameters

    • password: string

      The password to hash

    Returns string

  • Hash a password using Phpass.

    Returns

    A string with the hashed password

    Parameters

    • password: string

      The password to hash

    • iterations: number

      The number of iterations to initialize phpass with

    Returns string

  • Hash the password using sha1 and return a base64 string representation of the bytes.

    Returns

    A base64 encoded string of the sha1 hash

    Parameters

    • password: string

      the password to hash

    Returns string

  • Hash the password using sha1 and return a hex string representation of the bytes.

    Returns

    A string of hex characters

    Parameters

    • password: string

      the password to hash

    Returns string

  • Returns

    true if the provided password is the same as the comparable password. Always false if comparable password is null.

    Parameters

    • password: string

      The provided password

    • comparablePassword: null | string

      A hashed password to compare with

    Returns boolean

  • Generates a libc6 crypt() compatible $5$ SHA2 based hash value. The returned format is $5[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]. Use generateRandomSaltSha256 to generate a random salt.

    Returns

    The hashed password

    Parameters

    • password: string

      The provided password to hash

    • salt: string

      A formatted sha2 salt

    Returns string

  • Check if a provided password matches the stored password.

    Returns

    true if the provided password is the same as the comparable password. Always false if comparablePassword is null.

    Parameters

    • password: string

      The provided password

    • comparablePassword: null | string

      A hashed password to compare with

    Returns boolean

  • Generates a libc6 crypt() compatible $6$ SHA2 based hash value. The returned format is $6[$<param>=<value>(,<param>=<value>)*][$<salt>[$<hash>]]. Use generateRandomSaltSha512 to generate a random salt.

    Returns

    The hashed password

    Parameters

    • password: string

      The provided password to hash

    • salt: string

      A formatted sha2 salt

    Returns string