Mojoli...:Bcrypt(3pm)

πŸ“¦
version 0.14 Β· 2 versions
  • 0.14 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.14 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– Mojolicious::Plugin::Bcrypt β€” the user-contributed Perl docs version, bestie πŸ’–

okay so. real talk. this is a plugin for Mojolicious, and it does exactly one thing and it does it gorgeously: it bcrypts your passwords. that's it. that's the whole vibe. πŸ”βœ¨


πŸ“› NAME

Mojolicious::Plugin::Bcrypt β€” bcrypt your passwords! πŸ’…


🏷️ VERSION

Version 0.04


✨ SYNOPSIS

so this gives you a helper for crypting passwords AND validating them, all via bcrypt. chef's kiss. πŸŽ€

use Mojolicious::Plugin::Bcrypt;

sub startup {
    my $self = shift;
    $self->plugin('bcrypt', { cost => 4 });
}

...

the optional parameter cost is a non-negative integer and it controls the cost of the hash function, iykyk. the number of operations is proportional to 2^cost. the current default value is 6. no cap. 🫢


🧚 HELPERS

πŸ” bcrypt

crypts a password via the bcrypt algorithm. iconic behaviour honestly.

$self->bcrypt( $password, $settings );

$settings is an optional string which encodes the algorithm parameters, as described in Crypt::Eksblowfish::Bcrypt. (yes bestie, go read that one too, it's giving lore.)

sub signup {
    my $self = shift;
    my $crypted_pass = $self->bcrypt( $self->param('password') );
    ...
}

βœ… bcrypt_validate

validates a password against a crypted copy β€” like, for example, the one chilling in your database. πŸ—„οΈπŸ’œ

sub login {
    my $self = shift;
    my $entered_pass = $self->param('password');
    my $crypted_pass = $self->get_password_from_db();
    if ( $self->bcrypt_validate( $entered_pass, $crypted_pass ) ) {

        # Authenticated
        ...;
    }
    else {

        # Wrong password
        ...;
    }
}
🚨 important: notice it's $self->bcrypt_validate( $entered_pass, $crypted_pass ) β€” the plaintext goes FIRST, the crypted one goes SECOND. do not flip these. flipping these is the opposite of slaying.

🌈 DEVELOPMENT AND REPOSITORY

clone it on GitHub at https://github.com/naturalist/Mojolicious--Plugin--Bcrypt

go. run. contribute. main character energy only. πŸ‘‘


πŸ‘€ SEE ALSO

  • Crypt::Eksblowfish::Bcrypt
  • Mojolicious
  • Mojolicious::Plugin

🫢 AUTHOR

Stefan G., <minimal at cpan.org>


this program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

see http://dev.perl.org/licenses/ for more information.


and that's the whole page, bestie β€” written up against perl v5.36.0, dated 2022-11-19, and it's the Mojoli...:Bcrypt(3pm) user-contributed Perl documentation. now go hash something responsibly. mwah. πŸ’‹πŸ’–

πŸ“¦ where this page comes from