feat(Random): add hex characters set

This commit is contained in:
Matthieu Bessat 2021-08-21 21:48:33 +02:00
parent 9eb428c528
commit df790e0c9a
3 changed files with 7 additions and 2 deletions

View file

@ -2,7 +2,7 @@
$len = $_GET['length'] ?? 32; $len = $_GET['length'] ?? 32;
$contains = isset($_GET['contains']) ? explode(',', $_GET['contains']) : ['digit', 'upper', 'lower', 'special']; $contains = isset($_GET['contains']) ? explode(',', $_GET['contains']) : ['hex', 'digit', 'upper', 'lower', 'special'];
header('Content-Type: text/plain'); header('Content-Type: text/plain');

View file

@ -13,6 +13,10 @@ return [
[ [
'name' => 'Change length', 'name' => 'Change length',
'path' => '/?length=20' 'path' => '/?length=20'
],
[
'name' => 'Only hex',
'path' => '/?length=16&contains=hex'
] ]
], ],
'append' => function () { 'append' => function () {

View file

@ -5,7 +5,8 @@ function generateRandomString($length = 10, $contains = ['upper', 'lower', 'digi
'digit' => '0123456789', 'digit' => '0123456789',
'lower' => 'abcdefghijklmnopqrstuvwxyz', 'lower' => 'abcdefghijklmnopqrstuvwxyz',
'upper' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'upper' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
'special' => '!#$%&()*+,-.:;<=>?@[]' 'special' => '!#$%&()*+,-.:;<=>?@[]',
'hex' => '0123456789abcdef'
]; ];
$characters = ''; $characters = '';
foreach ($contains as $c) { foreach ($contains as $c) {