Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Add script and add exception.
James Cole0e97b4a6b8b5
diff --git a/public/v1/js/.gitignore b/public/v1/js/.gitignoreindex 9635b666d2..0ac0c2bc29 100644--- a/public/v1/js/.gitignore+++ b/public/v1/js/.gitignore@@ -1,3 +1,3 @@*.LICENSE.txt*.js-#webhooks+!ff/*/*.jsdiff --git a/public/v1/js/ff/auth/.htaccess b/public/v1/js/ff/auth/.htaccessnew file mode 100644index 0000000000..45552cb63e--- /dev/null+++ b/public/v1/js/ff/auth/.htaccess@@ -0,0 +1 @@+Options -Indexes\ No newline at end of filediff --git a/public/v1/js/ff/auth/register.js b/public/v1/js/ff/auth/register.jsnew file mode 100644index 0000000000..1632f7c8a0--- /dev/null+++ b/public/v1/js/ff/auth/register.js@@ -0,0 +1,98 @@+/*+ * register.js+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++(function () {+ const form = document.querySelector('form[action="'+route+'"]');+ const errorBox = document.getElementById('client-errors');+ const errorList = document.getElementById('client-errors-list');+ const submitBtn = form.querySelector('button[type="submit"]');+ const originalBtnText = submitBtn.textContent;++ function showErrors(errors) {+ errorList.innerHTML = errors.map(function(e) { return '<li>' + e + '</li>'; }).join('');+ errorBox.style.display = 'block';+ errorBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' });+ }++ async function sha1Hex(str) {+ const buf = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(str));+ return Array.from(new Uint8Array(buf))+ .map(function(b) { return b.toString(16).padStart(2, '0'); })+ .join('')+ .toUpperCase();+ }++ async function isPwned(password) {+ const hash = await sha1Hex(password);+ const prefix = hash.slice(0, 5);+ const suffix = hash.slice(5);+ const res = await fetch('https://api.pwnedpasswords.com/range/' + prefix, {+ headers: { 'Add-Padding': 'true' }+ });+ if (!res.ok) { return false; }+ const text = await res.text();+ return text.toUpperCase().split('\n').some(function(line) {+ return line.split(':')[0] === suffix;+ });+ }++ form.addEventListener('submit', async function (e) {+ e.preventDefault();+ errorBox.style.display = 'none';++ const password = form.querySelector('[name="password"]').value;+ const confirm = form.querySelector('[name="password_confirmation"]').value;+ const verify = form.querySelector('[name="verify_password"]');+ const errors = [];++ if (password.length < 16) {+ errors.push(passwordLengthError);+ }+ if (password !== confirm) {+ errors.push(passwordMatchError);+ }++ if (errors.length > 0) {+ showErrors(errors);+ return;+ }++ if (verify && verify.checked) {+ submitBtn.disabled = true;+ submitBtn.textContent = waitForVerify;+ try {+ if (await isPwned(password)) {+ errors.push(needSecurePassword);+ }+ } catch (_) {+ // network failure — let server validate+ }+ submitBtn.disabled = false;+ submitBtn.textContent = originalBtnText;+ }++ if (errors.length > 0) {+ showErrors(errors);+ return;+ }++ form.submit();+ });+})();diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.phpindex c39fc0a06d..64b003a3d9 100644--- a/resources/views/auth/register.blade.php+++ b/resources/views/auth/register.blade.php@@ -81,83 +81,11 @@@endsection@section('scripts')<script nonce="{{ $JS_NONCE }}">- (function () {- const form = document.querySelector('form[action="{{ route('register') }}"]');- const errorBox = document.getElementById('client-errors');- const errorList = document.getElementById('client-errors-list');- const submitBtn = form.querySelector('button[type="submit"]');- const originalBtnText = submitBtn.textContent;-- function showErrors(errors) {- errorList.innerHTML = errors.map(function(e) { return '<li>' + e + '</li>'; }).join('');- errorBox.style.display = 'block';- errorBox.scrollIntoView({ behavior: 'smooth', block: 'nearest' });- }-- async function sha1Hex(str) {- const buf = await crypto.subtle.digest('SHA-1', new TextEncoder().encode(str));- return Array.from(new Uint8Array(buf))- .map(function(b) { return b.toString(16).padStart(2, '0'); })- .join('')- .toUpperCase();- }-- async function isPwned(password) {- const hash = await sha1Hex(password);- const prefix = hash.slice(0, 5);- const suffix = hash.slice(5);- const res = await fetch('https://api.pwnedpasswords.com/range/' + prefix, {- headers: { 'Add-Padding': 'true' }- });- if (!res.ok) { return false; }- const text = await res.text();- return text.toUpperCase().split('\n').some(function(line) {- return line.split(':')[0] === suffix;- });- }-- form.addEventListener('submit', async function (e) {- e.preventDefault();- errorBox.style.display = 'none';-- const password = form.querySelector('[name="password"]').value;- const confirm = form.querySelector('[name="password_confirmation"]').value;- const verify = form.querySelector('[name="verify_password"]');- const errors = [];-- if (password.length < 16) {- errors.push('{{ blade_escape_js((string)trans('validation.min.string', ['attribute' => 'password', 'min' => 16])) }}');- }- if (password !== confirm) {- errors.push('{{ blade_escape_js(trans('validation.confirmed', ['attribute' => 'password'])) }}');- }-- if (errors.length > 0) {- showErrors(errors);- return;- }-- if (verify && verify.checked) {- submitBtn.disabled = true;- submitBtn.textContent = '{{ blade_escape_js(trans('validation.verifying_password')) }}';- try {- if (await isPwned(password)) {- errors.push('{{ blade_escape_js(trans('validation.secure_password')) }}');- }- } catch (_) {- // network failure — let server validate- }- submitBtn.disabled = false;- submitBtn.textContent = originalBtnText;- }-- if (errors.length > 0) {- showErrors(errors);- return;- }-- form.submit();- });- })();- </script>+ var route = '{{ route('register') }}';+ var passwordLengthError = '{{ blade_escape_js((string)trans('validation.min.string', ['attribute' => 'password', 'min' => 16])) }}';+ var passwordMatchError = '{{ blade_escape_js(trans('validation.confirmed', ['attribute' => 'password'])) }}';+ var waitForVerify = '{{ blade_escape_js(trans('validation.verifying_password')) }}';+ var needSecurePassword = '{{ blade_escape_js(trans('validation.secure_password')) }}';+ </script>+ <script nonce="{{$JS_NONCE}}" src="v1/js/ff/auth/register.js"></script>@endsection