package ONO::Lib::Code::RandomID;
################################################################################
# COPYRIGHT / LICENSE #
################################################################################
#
# This file is part of the ONO Software Project.
#
# Copyright (C) 2000-2025 Jos KIRPS [ www.kirps.com | jos_AT_kirps_DOT_com ]
# and The Joopita Project [ www.joopita.org | contact_AT_joopita_DOT_com ]
#
# This file, as well as other parts of the ONO Software Project or related
# elements, are FREE SOFTWARE available under the ARTISTIC LICENSE 2.0.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# For the full license, see /ono/osr/license/LICENSE.txt, or write to
# jos_AT_kirps_DOT_com or contact_AT_joopita_DOT_com.
#
################################################################################
# END OF COPYRIGHT / LICENSE, HERE COMES THE CODE ... #
################################################################################
use strict;
sub make {
#: Generate a random ID, default length is 10 chars.
#: Numbers and letters that may be confused are being avoided.
my $length = $_[1];
if ($length < 1) {
$length = 10;
}
my @chars = (
'2','3','4','5','6', '7','8','9','A','B',
'C','D','E','F','G', 'H','J','K','L','M',
'N','P','Q','R','S', 'T','U','V','W','X',
'Y','Z','a','b','c', 'd','e','f','g','h',
'i','j','k','m','n', 'o','p','q','r','s',
't','u','v','w','x', 'y','z','X','X','X',
);
my $id;
for (my $i = 0; $i < $length; $i++) {
$id .= $chars[int(rand(57))];
}
return $id;
}
sub num {
#: Generate a random number.
my $length = $_[1];
if ($length < 1) {
$length = 10;
}
my $id;
for (my $i = 0; $i < $length; $i++) {
$id .= int(rand(9));
}
return $id;
}
sub password {
#: Generate a password, default length is 8 chars.
#: Numbers and letters that may be confused are being avoided.
#: In most cases, you may also use make() to generate a password.
#: Note that generated passwords are not strong by default,
#: and they don't contain special characters.
#: Using 12 chars is recommended for passwords.
#: Note that the ONO login mechanisms offer some protection against
#: automated login hacking, at least if the attack is originating
#: from a single IP.
my $length = $_[1];
if ($length < 1) {
$length = 8;
}
my @chars1 = (
'A','C','F','G','H', 'J','K','L','M','N',
'P','R','L','T','U', 'V','W','X','Y','Z',
);
my @chars2 = (
'2','4','6','8','9', 'a','b','c','d','e',
'2','4','6','8','9', 'f','g','h','j','k',
'm','n','p','q','r', 's','t','w','x','z',
);
my $id .= $chars1[int(rand(20))];
for (my $i = 0; $i < $length-1; $i++) {
$id .= $chars2[int(rand(30))];
}
if ($length == 5) {
$id = $chars1[int(rand(20))];
$id .= lc $chars1[int(rand(20))];
$id .= int(rand(10));
$id .= int(rand(10));
$id .= int(rand(10));
}
return $id;
}
###############################################################################
# end of script
###############################################################################
1;
__END__