@sleep2agi/commhub-server 0.8.0-preview.0 → 0.8.0-preview.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/auth.ts +9 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sleep2agi/commhub-server",
|
|
3
|
-
"version": "0.8.0-preview.
|
|
3
|
+
"version": "0.8.0-preview.1",
|
|
4
4
|
"description": "CommHub Server — AI Agent communication hub with MCP protocol, multi-network isolation, user auth, and 18 MCP tools.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.ts",
|
package/src/auth.ts
CHANGED
|
@@ -30,16 +30,22 @@ function validatePasswordStrength(password: string, label = "password"): string
|
|
|
30
30
|
export function register(username: string, password: string, email?: string, displayName?: string): AuthResult {
|
|
31
31
|
if (!username || username.length < 2) return { ok: false, error: "username must be at least 2 characters" };
|
|
32
32
|
if (username.length > 50) return { ok: false, error: "username too long (max 50)" };
|
|
33
|
-
const passwordError = validatePasswordStrength(password);
|
|
34
|
-
if (passwordError) return { ok: false, error: passwordError };
|
|
35
33
|
if (!/^[a-zA-Z0-9_\-\u4e00-\u9fff]+$/.test(username)) return { ok: false, error: "username contains invalid characters" };
|
|
36
34
|
|
|
37
35
|
const existing = db.get<any>("SELECT user_id FROM users WHERE username = ?1", username);
|
|
38
36
|
if (existing) return { ok: false, error: "username already taken" };
|
|
39
37
|
|
|
40
|
-
// First user → auto admin
|
|
38
|
+
// First user → auto admin. Bootstrap admin may use a weak/memorable default
|
|
39
|
+
// password (e.g. "anethub") for quick start; they should rotate via
|
|
40
|
+
// `anet passwd` afterwards. Subsequent users must meet full strength.
|
|
41
41
|
const userCount = db.get<{ cnt: number }>("SELECT COUNT(*) as cnt FROM users");
|
|
42
42
|
const isFirstUser = !userCount || userCount.cnt === 0;
|
|
43
|
+
if (isFirstUser) {
|
|
44
|
+
if (!password || password.length < 4) return { ok: false, error: "password must be at least 4 characters" };
|
|
45
|
+
} else {
|
|
46
|
+
const passwordError = validatePasswordStrength(password);
|
|
47
|
+
if (passwordError) return { ok: false, error: passwordError };
|
|
48
|
+
}
|
|
43
49
|
|
|
44
50
|
const userId = generateId("u");
|
|
45
51
|
const pwHash = hashPassword(password);
|