generateBCryptHash

It is a password-hashing cryptographic function that takes an input and hashes it into a fixed size output./nNOTE: BCrypt input is limited to 72 bytes.

generateBCryptHash(plaintext,options); → returns string

This function requires Adobe ColdFusion 2021 and up.  Not supported on Lucee, etc.

generateBCryptHash Argument Reference

plaintext string
Required

The input string to hash.

options struct
Default: {"version":"$2a","rounds":10}

A struct containing the optional values:
--version - Version of BCrypt hash to generate ($2a,$2y or $2b). (Default is "$2a". The most current version is "$2b")
--rounds - Number of rounds to run the hash functions. (Default is 10.)
Values:
  • version
  • rounds

Links more information about generateBCryptHash

Examples sample code invoking the generateBCryptHash function

This is an example of using the function with no options.

secretMsg=generateBCryptHash("My voice is my passport. Verify me.");writeDump(secretMsg)

Expected Result: $2a$10$.jQX1KnwPzhvVet0vEENnOlO8C70oM8GQhu0MQnCgcIlWhguWb3q.

This is an example of using the function with optional version specified.

secretMsg=generateBCryptHash("My voice is my passport. Verify me.",{"version":"$2b"});
writeDump(secretMsg)

Expected Result: $2b$10$wkfNE0B2hP/GMqQPWRvTte87F/PlEZwetaDPnVwW5OjBRAPiGKZp.

This is an example of using the function with optional rounds specified.

secretMsg=generateBCryptHash("Setec Astronomy",{"rounds":15});writeDump(secretMsg)

Expected Result: $2a$15$yBUewN8dYFd9QawytI5SO.MIq0hO65TXEoVyUAZRlK.oTHZ4Dwa0i


Fork me on GitHub