shorten public links to 8 characters

Signed-off-by: dartcafe <github@dartcafe.de>
This commit is contained in:
dartcafe 2023-03-27 20:57:10 +02:00
Родитель f1accf4585
Коммит 32884fd867
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: CCE73CEF3035D3C8
2 изменённых файлов: 25 добавлений и 6 удалений

Просмотреть файл

@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file.
- Added qr code for public shares - Added qr code for public shares
### Changes ### Changes
- PHP 8.0 as minimum requirement - PHP 8.0 as minimum requirement
- Shorten public tokens to 8 characters (lower and upper characters and digits)
## [4.1.5] - 2023-02-25 ## [4.1.5] - 2023-02-25
### Fix ### Fix

Просмотреть файл

@ -422,12 +422,30 @@ class ShareService {
string $timeZone = '' string $timeZone = ''
): Share { ): Share {
$preventInvitation = $userGroup->getType() === UserBase::TYPE_PUBLIC ?: $preventInvitation; $preventInvitation = $userGroup->getType() === UserBase::TYPE_PUBLIC ?: $preventInvitation;
$token = $this->secureRandom->generate(
16, $token = null;
ISecureRandom::CHAR_DIGITS . $loopCounter = 0;
ISecureRandom::CHAR_LOWER . // Generate a unique id
ISecureRandom::CHAR_UPPER while (!$token) {
); $loopCounter++;
$token = $this->secureRandom->generate(
8,
ISecureRandom::CHAR_DIGITS .
ISecureRandom::CHAR_LOWER .
ISecureRandom::CHAR_UPPER
);
try {
$this->shareMapper->findByToken($token);
// reset token, if it already exists
$token = null;
} catch (ShareNotFoundException) {
$loopCounter = 0;
}
if ($loopCounter > 10) {
// In case of uninspected situations, avoid an endless loop
throw new \Exception('Unexpected loop count while trying to create a token for a new share');
}
}
$this->share = new Share(); $this->share = new Share();
$this->share->setToken($token); $this->share->setToken($token);