This article will demonstrate how to use a Perl Random Password Generator to create a cryptographically secure password. The library used is the Bytes::Random::Secure extension which provides a flexible Object Oriented interface for greater control, and also simple functions that are usable for basic requirements. This article will focus on the simple functions provided by default.
Perl Install Bytes::Random::Secure
The examples in this article are using perl on Windows. To install the Bytes::Random::Secure perl extension on Windows run the following command using the ppm (Perl Package Manager) utility.
ppm install Bytes-Random-SecureUse the Bytes::Random::Secure library
In your perl script, initialize the Bytes::Random::Secure library.
use Bytes::Random::Secure qw(
random_bytes random_bytes_base64 random_bytes_hex random_string_from
);The examples below will make use of the simple functions in the extension that are explicitly included.
Perl Generate Random Bytes
Using the random_bytes interface, provide the number of random bytes you wish to generate.
my $bytes = random_bytes(30);Perl Generate Random String
Using the random_string_from interface, provide a range of characters and length of string as parameters. This function is commonly used for generating a secure random password in perl.
my $bytes = random_string_from('abcdefghijklmnopqrstuvwxyz0123456789', 30); Perl Generate Random Bytes Base64 Encoded
Using the random_bytes_base64 interface, provide a length of random bytes to be encoded.
my $bytes_as_base64 = random_bytes_base64(30);Perl Generate Random Hex
Using the random_bytes_hex interface, provide a length of random bytes as hex digits.
my $bytes_as_hex = random_bytes_hex(30);Conclusion – Perl Random Password Generator
This article has demonstrated how to generate secure random passwords, string, bytes, and more using the Bytes::Random::Secure library in Perl as well as how to install and instantiate it. Let us know in the comments if you have any questions or would like to see additional examples. If you found this article helpful, read more of our content on perl.
Leave a Reply