Skip to content
Snippets Groups Projects
Commit 3faba161 authored by Guillaume ROUSSE's avatar Guillaume ROUSSE
Browse files

more readability

parent 5c98e1c3
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ use Digest::SHA;
use Digest::MD5;
use Encode;
use English qw(-no_match_vars);
use List::Util qw(shuffle);
use List::MoreUtils qw(pairwise);
use MIME::Base64;
use Template;
......@@ -49,49 +50,28 @@ sub sha256_hash {
# This function generates a random password
sub generate_password {
my $length_of_randomstring = 10; # the length of
# the random string to generate
# plusieurs tirages :
# 1-tirage des caractères obligatoires : les mettre dans un tableau
my @uppers = ('A' .. 'N', 'P' .. 'Z');
my @lowers = ('a' .. 'k', 'm' .. 'z');
my @punctuation = (':', '!', '?', '&', '$', '=', '-', '#');
my @numerics = ('0' .. '9');
my @rndtab;
push(@rndtab, $uppers[ rand @uppers ]);
push(@rndtab, $lowers[ rand @lowers ]);
push(@rndtab, $punctuation[ rand @punctuation ]);
## Pas de caractères 8bit pour l'antispam
push(@rndtab, $numerics[ rand @numerics ]);
# 2-tirage des caractères optionnels : les ajouter au tableau
my $size = 10;
my @uppers = ('A' .. 'N', 'P' .. 'Z');
my @lowers = ('a' .. 'k', 'm' .. 'z');
my @punctuations = (':', '!', '?', '&', '$', '=', '-', '#');
my @numerics = ('0' .. '9');
my @all = (@uppers, @lowers, @punctuations, @numerics);
# start with a random character of each class
my @chars = (
'a' .. 'k', 'm' .. 'z', 'A' .. 'N', 'P' .. 'Z',
'0' .. '9', '_', '%', ';',
':', '!', '?', '&',
'$', '*', '(', ')',
'{, }', '[', ']',
'.', '=', '-', '#'
$uppers[ rand @uppers ],
$lowers[ rand @lowers ],
$punctuations[ rand @punctuations ],
$numerics[ rand @numerics ]
);
foreach (5 .. $length_of_randomstring) {
# rand @chars will generate a random
# number between 0 and scalar @chars
push(@rndtab, $chars[ rand @chars ]);
# complete with additional characters
for my $i (1 .. $size - 4) {
push(@chars, $all[ rand @all ]);
}
# 3-ordonnancement de ceux-ci : les retirer aléatoirement du tableau en les concaténant dans une chaîne
my $rndstring = '';
my $cpt = 1;
while ($cpt <= $length_of_randomstring) {
my $indice = rand @rndtab;
$rndstring .= $rndtab[$indice];
splice(@rndtab, $indice, 1);
$cpt += 1;
}
return $rndstring;
return join('', shuffle(@chars));
}
# ID is based on time + PID
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment