Set the cloud code length as a DataBase constant

This commit is contained in:
Gregory Trolliet 2020-11-25 22:49:54 +01:00
parent 06de0eb561
commit e072182ed4
2 changed files with 3 additions and 2 deletions

View file

@ -29,8 +29,7 @@ if (empty($_POST)) {
</div> </div>
<?php <?php
} else { } else {
$length = 6; $token = bin2hex(random_bytes(DataBase::CLOUD_CODE_LENGTH));
$token = bin2hex(random_bytes($length));
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) { if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
$size = $_POST['fsize']; $size = $_POST['fsize'];
} else { } else {
@ -50,6 +49,7 @@ if (empty($_POST)) {
while (!$db->createCloud($token, $text, $size, $duration) && $cpt < 10) { while (!$db->createCloud($token, $text, $size, $duration) && $cpt < 10) {
$token = bin2hex(random_bytes($length)); $token = bin2hex(random_bytes($length));
$cpt++; $cpt++;
// TODO what to do if no cloud created?
} }
$viewUrl = 'result.php?id=' . $token; $viewUrl = 'result.php?id=' . $token;
$viewName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewUrl; $viewName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewUrl;

1
db.php
View file

@ -12,6 +12,7 @@ class DataBase
'month' => '+1 month' 'month' => '+1 month'
); );
const DEFAULT_SIZE = 3; const DEFAULT_SIZE = 3;
const CLOUD_CODE_LENGTH = 6;
private $db; private $db;
private $cloud; private $cloud;