How do you use password hashing (Crypt::Argon2, bcrypt) with a short example?

Password hashing is a crucial aspect of application security that helps protect user passwords from unauthorized access. Two popular methods for password hashing in Perl are Crypt::Argon2 and bcrypt. Below is a simple example demonstrating how to use both methods for securely hashing passwords.

# Using Crypt::Argon2 use Crypt::Argon2; my $password = 'my_secure_password'; my $argon2 = Crypt::Argon2->new(); # Hashing a password my $hashed_password = $argon2->generate($password); print "Argon2 Hashed Password: $hashed_password\n"; # Verifying a password if ($argon2->verify($hashed_password, $password)) { print "Password verification successful!\n"; } else { print "Password verification failed.\n"; } # Using bcrypt use Crypt::Bcrypt; # Hashing a password with bcrypt my $bcrypt_hash = Crypt::Bcrypt::bcrypt($password); print "Bcrypt Hashed Password: $bcrypt_hash\n"; # Verifying a password if (Crypt::Bcrypt::bcrypt_verify($password, $bcrypt_hash)) { print "Password verification successful!\n"; } else { print "Password verification failed.\n"; }

password hashing Crypt::Argon2 bcrypt Perl security