Fixes in generate_random_password

This commit is contained in:
absurdo 2023-07-08 00:31:37 +02:00
parent 3f22c5c267
commit 9ffababf66

View file

@ -34,41 +34,6 @@ class Utils {
static public function slugify($text, $respect_upper=0, $replace_space='-', $replace_dot=0, $replace_barr=0) static public function slugify($text, $respect_upper=0, $replace_space='-', $replace_dot=0, $replace_barr=0)
{ {
/*
$from='àáâãäåæçèéêëìíîïðòóôõöøùúûýþÿŕñÀÁÂÃÄÅÇÈÉÊËÌÍÎÏÐÒÓÔÕÖØÙÚÛÝỲŸÞŔÑ¿?!¡()"|#*%,;+&$ºª<>`çÇ{}@~=^:´[]';
$to= 'aaaaaaaceeeeiiiidoooooouuuybyrnAAAAAACEEEEIIIIDOOOOOOUUUYYYBRN---------------------------------';
if($replace_dot==1)
{
$from.='.';
$to.='-';
}
if($replace_barr==1)
{
$from.="/";
$to.="-";
}
$text = utf8_decode(urldecode($text));
$text=trim(str_replace(" ", $replace_space, $text));
$text = strtr($text, utf8_decode($from), $to);
//Used for pass base64 via GET that use upper, for example.
if($respect_upper==0)
{
$text = strtolower($text);
}*/
$text=iconv('utf-8', 'us-ascii//TRANSLIT', $text); $text=iconv('utf-8', 'us-ascii//TRANSLIT', $text);
@ -373,7 +338,7 @@ class Utils {
} }
/** /**
* Function used for generate a simple random password. Used RamdomLib from Ircmaxell * Function used for generate a simple random password. Use random_int php function for get the characters of the password
* *
* @param string $length_pass A variable used for set the character's length the password. More length, password more secure * @param string $length_pass A variable used for set the character's length the password. More length, password more secure
* *
@ -387,30 +352,36 @@ class Utils {
$abc=array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '+', '!', '-', '_', '@', '#', '$'); $abc=array( 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '*', '+', '!', '-', '_', '@', '#', '$');
$password_final=''; $disorder_abc=[];
$c=count($abc); //Simple disorder using random_int
while(count($abc)>0) {
$c_abc=count($abc);
$num_element_move=random_int(0, $c_abc-1);
$disorder_abc[]=$abc[$num_element_move];
unset($abc[$num_element_move]);
$abc=array_values($abc);
}
$c=count($disorder_abc);
$password_final='';
for($x=0;$x<$length_pass;$x++) { for($x=0;$x<$length_pass;$x++) {
$num_element_pass=random_int(0, $c-1); $num_element_pass=random_int(0, $c-1);
$password_final.=$abc[$num_element_pass]; $password_final.=$disorder_abc[$num_element_pass];
} }
/*$password_final=bin2hex(random_bytes(round($length_pass/2)));
$num_element_pass=random_int(0, 5);
$abc=['*', '+', '!', '-', '_', '@', '#', '$'];
for($x=0;$x<$num_element_pass;$x++) {
$num_change_char=random_int(0, len($abc));
}*/
//Add strange characters //Add strange characters
return $password_final; return $password_final;