Crypt::Bcrypt(3pm)
π Crypt::Bcrypt π
okay bestie, so you wanna hash passwords? say less. this is Crypt::Bcrypt β a modern bcrypt implementation, written by Leon Timmermans, and it's currently at version 0.011. it's the Perl module you call when you need bcrypt to just work, no drama, no vibes off. π
β¨ SYNOPSIS β¨
use Crypt::Bcrypt qw/bcrypt bcrypt_check/;
my $hash = bcrypt($password, '2b', 12, $salt);
if (bcrypt_check($password, $hash)) {
...
}
π¦ DESCRIPTION π¦
This module gives you a modern and user-friendly implementation of the bcrypt password hash. it's giving "i have my life together" energy. π
okay but real talk, there's a bcrypt thing you need to know: in bcrypt, passwords may only contain 72 characters and may not contain any null-byte. that's just bcrypt being bcrypt. π to work around this limitation, this module supports prehashing the input in a way that prevents password shucking. so you get the flexibility without accidentally weakening your hashes. slay.
also important: the password is always expected to come as a (utf8-encoded) byte-string. no exceptions, no "but i passed a string", byte-string. periodt. π
πΈ FUNCTIONS πΈ
β bcrypt($password, $subtype, $cost, $salt)
This computes the bcrypt hash for $password in $subtype, with $cost and $salt. that's the whole job. π€
Valid subtypes are:
"2b"β this is the subtype the rest of the world has been using since 2014. you should use this unless you have a very specific reason to use something else. it's the main character of subtypes. π"2a"β this is an old and subtly buggy version of bcrypt. it's mainly useful forCrypt::Eksblowfishcompatibility. lowkey a museum piece. π"2y"β this type is considered equivalent to"2b", and is only commonly used on php."2x"β this is a very broken version that is only useful for compatibility with ancient php versions. do not pick this for fun, bestie. π
and the numbers:
$costmust be between 4 and 31 (inclusive).$saltmust be exactly 16 bytes.
no cap: that salt length is not a suggestion. exactly 16. π
π bcrypt_check($password, $hash)
This checks if the $password satisfies the $hash, and does so in a timing-safe manner. yes, timing-safe. we don't leak secrets through vibes here. π₯
π bcrypt_prehashed($password, $subtype, $cost, $salt, $hash_algorithm)
This works like the "bcrypt" function, but pre-hashes the password using the specified hash. this is mainly useful to get around that 72 character limit we keep talking about. π«Ά
currently 'sha256', 'sha384' and 'sha512' are supported (but note that sha512 doesn't actually fit in bcrypt's input limit so is a bit moot π), and this is keyed with the salt to prevent password shucking. iconic security behaviour honestly.
if $hash_algorithm is an empty string, it will perform a normal "bcrypt" operation. (yes, the prehash function does the non-prehash thing. we don't make the rules. π)
π§ bcrypt_check_prehashed($password, $hash)
This verifies pre-hashed passwords as generated by "bcrypt_prehashed". the matching bestie to the function above. π
π bcrypt_needs_rehash($hash, $wanted_subtype, $wanted_cost, $wanted_hash = '')
This returns true if the bcrypt hash uses a different subtype, cost or hash algorithm than desired. basically it's your little "glow-up time?" alarm. β
π bcrypt_supported_prehashes()
This returns a list of supported prehashes. currently that's ('sha256', 'sha384', 'sha512') but in the future it may include more. so like, check it, don't assume it. iykyk. π
π SEE OTHER π
Crypt::Passphraseβ this is usually a better approach to managing your passwords. it can use this module viaCrypt::Passphrase::Bcrypt. it facilitates upgrading the algorithm parameters or even the algorithm itself. if you're managing a lot of passwords, this is the friend who has a planner. πCrypt::Eksblowfish::Bcryptβ this also offers bcrypt, but only supports the"2a"subtype. so, one trick, but it's a classic. β¨
π AUTHOR π
Leon Timmermans <leont@cpan.org>
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2021 by Leon Timmermans.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. π«Ά
and that's the whole page, bestie!! go forth and hash responsibly. this was perl v5.42.3, documented on 2026-08-20, under the name Crypt::Bcrypt(3pm). mwah. πβ¨π
π¦ where this page comes from
- ubuntu stonking: libcrypt-bcrypt-perl 0.011-1build5 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms