NAME

Crypt::URandom::Password - Generate passwords from cryptographically secure pseudorandom bytes

SYNOPSIS

# Function usage:

use Crypt::URandom::Password qw(password);
my $password = urandom_password(); # generates a 44-character alphanumeric password

# Object usage:

use Crypt::URandom::Password;
my $obj = Crypt::URandom::Password->new(
    length   => 44,
    alphabet => [ A..Z, a..z, 0..9 ],
);
my $password = $obj->get;

DESCRIPTION

This module provides a secure way to generate a random string for passwords and similar using Crypt::URandom as a source of random bits.

By default, it generates an alphanumeric password with more than 256 bits of entropy, which should be sufficient for most purposes as of 2025.

FUNCTIONS

urandom_password($length = 44, $alphabet = [ A..Z, a..z, 0..9 ]);

Returns a cryptographically secure random string suitable for password.

If $length is not provided, it defaults to 44.

If $alphabet is not provided, it defaults to uppercase letters, lowercase letters, and digits. You can provide either a string of characters or an arrayref.

METHODS

new

Creates a new password generator object. Accepts a hash or hashref with these paramters:

  • length - desired password length (defaults to 44)

  • alphabet - the set of characters to use. Can be a string (split into individual chars) or an array reference. Defaults to [ A..Z, a..z, 0..9 ]

get

Generates and returns a random password as a string, using the object's attributes for length and alphabet.

AUTHOR

Stig Palmquist <stig@stig.io>

LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.