misc: updates, cleanups.

This commit is contained in:
Darshan
2026-01-26 16:10:51 +05:30
parent 8b9051751a
commit 7fb654e3a4
3 changed files with 16 additions and 5 deletions
+3 -2
View File
@@ -446,10 +446,11 @@
valid = false;
}
if (!password || !password.value.trim()) {
const passwordValue = password?.value ?? '';
if (!password || !/\S/.test(passwordValue)) {
setFieldError?.(password, 'Please enter a password');
valid = false;
} else if (!isValidPassword?.(password.value.trim())) {
} else if (!isValidPassword?.(passwordValue)) {
setFieldError?.(password, 'Password must be at least 8 characters');
valid = false;
}
@@ -298,7 +298,7 @@ class HttpHandler
$input['emailCertificates'] = $emailCertificates;
$opensslKey = trim((string) ($input['opensslKey'] ?? ''));
if ($opensslKey === '' || strlen($opensslKey) > 64) {
if (!$this->state->isValidSecretKey($opensslKey)) {
$this->respondBadRequest('Secret API key must be 1-64 characters', $wantsStream);
}
$input['opensslKey'] = $opensslKey;
@@ -308,7 +308,7 @@ class HttpHandler
if (!$this->config->isUpgrade()) {
$accountName = trim((string) ($input['accountName'] ?? ''));
if ($accountName === '') {
if (!$this->state->isValidAccountName($accountName)) {
$this->respondBadRequest('Please enter a name', $wantsStream, Server::STEP_ACCOUNT_SETUP);
}
@@ -318,7 +318,7 @@ class HttpHandler
}
$accountPassword = (string) ($input['accountPassword'] ?? '');
if (!preg_match('/\\S/', $accountPassword) || !$this->state->isValidPassword($accountPassword)) {
if (!$this->state->isValidPassword($accountPassword)) {
$this->respondBadRequest('Password must be at least 8 characters', $wantsStream, Server::STEP_ACCOUNT_SETUP);
}
@@ -143,6 +143,16 @@ class State
return strlen($value) >= 8 && preg_match('/\S/', $value) === 1;
}
public function isValidSecretKey(string $value): bool
{
return $value !== '' && strlen($value) <= 64;
}
public function isValidAccountName(string $value): bool
{
return trim($value) !== '';
}
public function isValidAppDomainInput(string $value): bool
{
$value = trim($value);