GenerateBCryptHash

Description

It is a password-hashing cryptographic function that takes an input and hashes it into a fixed size output.

Syntax

GenerateBCryptHash(plaintext, options)

History

ColdFusion (2021 release): Added this function.

Parameters

Parameter

Description

plaintext

(Required) The input string on which the hash function must be run.

options

(Optional) A struct with the following values:

  • version- Version of the BCrypt hash to generate ("$2a","$2y" or "$2b"). Default is "$2a".
  • rounds - Number of rounds to run the hash functions. Default is 10.

Example

<cfscript> 
    stringToEncrypt = "Sample string" 
    options = StructNew() 
    options.rounds = 4 
    options.version = "$2a" 
    bcrypted = GenerateBCryptHash(stringToEncrypt, options) 
    writeDump(bcrypted) 
</cfscript>

Output

$2a$04$3rPqpEgx3CIZEVybl3myYu/IxZMttS5.DAX/WMZN8LYTCtU0oJY9G