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; ...@@ -7,6 +7,7 @@ use Digest::SHA;
use Digest::MD5; use Digest::MD5;
use Encode; use Encode;
use English qw(-no_match_vars); use English qw(-no_match_vars);
use List::Util qw(shuffle);
use List::MoreUtils qw(pairwise); use List::MoreUtils qw(pairwise);
use MIME::Base64; use MIME::Base64;
use Template; use Template;
...@@ -49,49 +50,28 @@ sub sha256_hash { ...@@ -49,49 +50,28 @@ sub sha256_hash {
# This function generates a random password # This function generates a random password
sub generate_password { sub generate_password {
my $length_of_randomstring = 10; # the length of my $size = 10;
# the random string to generate
my @uppers = ('A' .. 'N', 'P' .. 'Z');
# plusieurs tirages : my @lowers = ('a' .. 'k', 'm' .. 'z');
# 1-tirage des caractères obligatoires : les mettre dans un tableau my @punctuations = (':', '!', '?', '&', '$', '=', '-', '#');
my @uppers = ('A' .. 'N', 'P' .. 'Z'); my @numerics = ('0' .. '9');
my @lowers = ('a' .. 'k', 'm' .. 'z'); my @all = (@uppers, @lowers, @punctuations, @numerics);
my @punctuation = (':', '!', '?', '&', '$', '=', '-', '#');
my @numerics = ('0' .. '9'); # start with a random character of each class
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 @chars = ( my @chars = (
'a' .. 'k', 'm' .. 'z', 'A' .. 'N', 'P' .. 'Z', $uppers[ rand @uppers ],
'0' .. '9', '_', '%', ';', $lowers[ rand @lowers ],
':', '!', '?', '&', $punctuations[ rand @punctuations ],
'$', '*', '(', ')', $numerics[ rand @numerics ]
'{, }', '[', ']',
'.', '=', '-', '#'
); );
foreach (5 .. $length_of_randomstring) {
# rand @chars will generate a random # complete with additional characters
# number between 0 and scalar @chars for my $i (1 .. $size - 4) {
push(@rndtab, $chars[ rand @chars ]); push(@chars, $all[ rand @all ]);
} }
# 3-ordonnancement de ceux-ci : les retirer aléatoirement du tableau en les concaténant dans une chaîne return join('', shuffle(@chars));
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;
} }
# ID is based on time + PID # 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