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

1
db.php
View File

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