BoxLang 🚀 A New JVM Dynamic Language Learn More...
BCrypt's primary usage would be for the secure hashing of passwords. The hashing method provides a high level of security, but also makes it too slow use as a simple digest. It is also not reversible, and therefore is not suitable for encrypting transmission data.
More information about BCrypt:
Install the module via Commandbox, which will ensure all dependencies are installed as well:
box install bcrypt
cbjavaloader module ( automatically installed as a
dependency by Forgebox )A compiled version (0.4) of jBCrypt is listed as a dependency for the test harness. You can update the version by following the steps below.
test-harness/box.json dependency with the
correct version informationbox install from within the
test-harness directoryant -f test-harness/resources/jBCrypt-[version
number]/build.xml and move the generated
jbcrypt.jar file to models/lib
This module registers a wirebox mapping to the Bcrypt singleton,
BCrypt@BCrypt, which you may inject or instantiate in
your componets:
// Long Format
property name="BCrypt" inject="BCrypt@BCrypt";
// Module Alias Shortcut
property name="BCrypt" inject="@BCrypt";
or via getInstance() ( a ColdBox framework supertype
method ) inside your handlers, views, interceptors, etc.
getInstance( "BCrypt@BCrypt" )
getInstance( "@BCrypt" )
We have also created three mixin helpers that will be injected to all
your handlers, interceptors, layouts and views: bcryptHash(),
bcryptCheck(), bcryptSalt()
/**
* Hashes an incoming input string according to work factor and salt
*
* @password The input password to encrypt
* @workFactor Optional work factor
*
* @return The bcrypted password
*/
string function bcryptHash(
required string password,
workFactor,
salt
)
/**
* Check if the incoming candidate is the same as a bcrypthash, usually the best check for comparing them.
*
* @candidate The plain text string to compare against the encrypted hash
* @bCryptHash The bCrypt hash to compare it to
*
* @return True - if the match, false if they dont!
*/
boolean function bcryptCheck( required string candidate, required string bCryptHash )
/**
* Generates a salt for you.
*
* @workFactor The workfactor to use for the salt, by default we use the one in the settings
*/
string function bcryptSalt( workFactor )
The hashed password should be persisted so candidate passwords (submitted from login) can be checked against.
var hashedPassword = getInstance( "BCrypt" ).hashPassword( plaintextPassword );
The plaintextPasswordCandidate is the password the user
submits for authentication. The hashed password is retrieved for the
user being authenticated.
var isSamePassword = getInstance( "BCrypt" ).checkPassword( plaintextPasswordCandidate, hashedPassword );
Internally we generate a salt for you according to the
default work factor. You can however, alter this and pass in your own salt:
var hashedPassword = getInstance( "BCrypt" ).hashPassword(
password : plaintextPassword,
salt : mySalt
);
WorkFactor is an input to BCrypt that controls how long
(generally) it takes to hash a password. The module sets a default
value of 12. You should experiment to find the optimal
value for your environment. It should take as long as possible to
hash a password without being burdensome to your users on login. Half
a second to a full second is generally a good target to shoot for.
You can also set the workFactor on a per-call basis by passing it in
as a second parameter to the hashPassword method like so:
var hashedPassword = getInstance( "@BCrypt" ).hashPassword( plaintextPassword, 7 );
You may override the default work factor by creating a
BCrypt settings struct in your ColdBox.cfc
under the moduleSettings struct:
moduleSettings = {
bcrypt = {
workFactor = 15
}
};
Copyright Since 2005 ColdBox Framework by Luis Majano and Ortus Solutions, Corp www.coldbox.org | www.luismajano.com | www.ortussolutions.com
Because of His grace, this project exists. If you don't like this, then don't read it, its not for you.
"Therefore being justified by faith, we have peace with God through our Lord Jesus Christ: By whom also we have access by faith into this grace wherein we stand, and rejoice in hope of the glory of God. And not only so, but we glory in tribulations also: knowing that tribulation worketh patience; And patience, experience; and experience, hope: And hope maketh not ashamed; because the love of God is shed abroad in our hearts by the Holy Ghost which is given unto us. ." Romans 5:5
"I am the way, and the truth, and the life; no one comes to the Father, but by me (JESUS)" Jn 14:1-12
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
workfactor to be used in hashPassword()bcryptHash(), bcryptCheck(), bcryptSalt()generateSalt( workFactor = default ): bcryptSalt()salt argument via the hashPassword( input, workFactor, salt ) methodcompatiblity : New moduleSettings configuration as per ColdBox 5+ instead of parsing parent settings
$
box install BCrypt