Package: Cryptography

Class: BCrypt

Introduction

Environment: container

Bcrypt is a cryptographic hash function designed for password hashing and safe storing in the backend of applications in a way that is less susceptible to dictionary-based cyberattacks.

It accepts the following attributes

  • identifier: the hash alogorithm identifier, it can be '2a' or '2b'. The default value is '2b'.

  • password: The plain text password to be hashed.

  • round: A numeric cost is added in front of the salt and the password hashes, showing how many password iterations were made before the hash was generate. The default value is 12.

  • salt: A 16-byte salt value is added in front of the plain text password, it is random by default.

After configuring the attributes, the token method can be leveraged to obtain the hashed password.

For example:

bcrypt := BCrypt new.
bcrypt identifier: '2b'.
bcrypt password: 'password'.
bcrypt salt: #[40 38 165 61 211 214 154 81 150 63 16 222 93 78 171 1].
bcrypt round: 10.

" The hashed password can be added to a web hook's http header as follows in a talk rule: "
self httpHeaders at: 'authentication' put: bcrypt token.

Instance Method

Category: accessing

  • identifier - Get the identifier of the BCrypt.

  • identifier: - Set the identifier of the BCrypt.

  • password - Get the password of the BCrypt.

  • password: - Set the password of the BCrypt.

  • round - Get the round of the BCrypt.

  • round: - Set the round of the BCrypt.

  • salt - Get the salt of the BCrypt.

  • salt: - Set the salt of the BCrypt.

Category: encode

  • token - Answer the hashed password as a string.

    For example:

    bcrypt := BCrypt new.
    bcrypt password: 'password'.
    bcrypt token.

Last updated