Generate share passwords and offer them again beside the new link
Uploaders no longer have to make up a share password. With "Password protect" on, the upload page has Generate and Copy under the field, and the page the upload leads to offers the password once more beside the link: masked, with the same copy button at the end of the field as the link's. The password also derives the share's encryption key and only its hash is stored, so a lost one means files nobody can open. - PasswordGeneratorService draws from Random\Randomizer's secure engine. Characters are drawn uniformly and redrawn until every chosen set appears; passphrases come from EFF's large word list (CC BY 3.0 US, credited in the README), without its four hyphenated words. - Admin settings gain a "Share Passwords" card: mode (off, on request, prefilled as protection is switched on), kind (characters: length 12–64, the sets, look-alikes left out; passphrase: 4–10 words and a separator), and an example with its estimated entropy that follows the form before saving. Fields the chosen mode or kind hides are excluded from validation and keep their saved value. The default is on request, 20 letters and numbers without look-alikes. - FileUploader flashes the password encrypted with the share's token; ShareCreated shows it only when the token matches, so a reload or any other visitor sees nothing. Crypt covers installs without SESSION_ENCRYPT, which the Docker setup does not set. - The symbol set leaves out what chat apps turn into formatting and what breaks inside quotes, so a pasted password arrives unchanged. - app.css imports group.css for <x-group>; .ai/rules/views.md records that <x-group> drops data-test and other attributes. - Tests cover the generator, the admin card's saving, validation and example, prefill and generate on the upload page, the flash, and in Chromium Generate and Copy on the upload page and the masked copy on the share page. The admin settings page now has six headed sections. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
a88a052d9a
commit
504971ad7f
@@ -3,7 +3,9 @@
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Setting;
|
||||
use App\Services\PasswordGeneratorService;
|
||||
use App\Services\ShareService;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
use Livewire\Attributes\Layout;
|
||||
@@ -101,6 +103,29 @@ class FileUploader extends Component
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in a generated password as protection is switched on, when the admin chose "Prefilled".
|
||||
* A password already in the field stays.
|
||||
*/
|
||||
public function updatedUsePassword(bool $value): void
|
||||
{
|
||||
$passwordGenerator = app(PasswordGeneratorService::class);
|
||||
|
||||
if ($value && $this->password === '' && $passwordGenerator->mode() === 'prefill') {
|
||||
$this->password = $passwordGenerator->generate();
|
||||
}
|
||||
}
|
||||
|
||||
public function generatePassword(PasswordGeneratorService $passwordGenerator): void
|
||||
{
|
||||
if ($passwordGenerator->mode() === 'off') {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->password = $passwordGenerator->generate();
|
||||
$this->resetErrorBag('password');
|
||||
}
|
||||
|
||||
public function removeFile(int $index): void
|
||||
{
|
||||
unset($this->files[$index], $this->relativePaths[$index]);
|
||||
@@ -184,6 +209,15 @@ class FileUploader extends Component
|
||||
'max_downloads' => $this->maxDownloads ?: null,
|
||||
]);
|
||||
|
||||
// The page the upload leads to offers the password once more, next to the link; it is
|
||||
// never stored in the clear, so this flash is the only way it gets there.
|
||||
if ($this->usePassword) {
|
||||
session()->flash('share_password', [
|
||||
'token' => $share->token,
|
||||
'password' => Crypt::encryptString($this->password),
|
||||
]);
|
||||
}
|
||||
|
||||
$this->redirect(route('share.created', $share), navigate: true);
|
||||
}
|
||||
|
||||
@@ -197,6 +231,7 @@ class FileUploader extends Component
|
||||
'siteDescription' => Setting::get('site_description'),
|
||||
'siteLogo' => Setting::get('site_logo'),
|
||||
'allowNeverExpire' => (bool) Setting::get('allow_never_expire', false),
|
||||
'passwordGeneratorMode' => app(PasswordGeneratorService::class)->mode(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user