mirror of
https://github.com/MengMengCode/VoCat.git
synced 2026-08-18 05:43:42 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c26f56af10 | ||
|
|
251c9f5de7 | ||
|
|
8f35a4520e |
@@ -10,6 +10,7 @@
|
|||||||
*.dll
|
*.dll
|
||||||
*.so
|
*.so
|
||||||
*.dylib
|
*.dylib
|
||||||
|
/fix
|
||||||
|
|
||||||
# ---- Cookie / secret files (NEVER commit) ----
|
# ---- Cookie / secret files (NEVER commit) ----
|
||||||
vc.jar
|
vc.jar
|
||||||
|
|||||||
@@ -29,8 +29,8 @@ func runBootstrapAdmin(args []string) error {
|
|||||||
return fmt.Errorf("read password: %w", err)
|
return fmt.Errorf("read password: %w", err)
|
||||||
}
|
}
|
||||||
password = strings.TrimSuffix(strings.TrimSuffix(password, "\n"), "\r")
|
password = strings.TrimSuffix(strings.TrimSuffix(password, "\n"), "\r")
|
||||||
if len(password) < 12 || len(password) > 1024 {
|
if len(password) < 6 || len(password) > 1024 {
|
||||||
return errors.New("bootstrap password must contain between 12 and 1024 characters")
|
return errors.New("bootstrap password must contain between 6 and 1024 characters")
|
||||||
}
|
}
|
||||||
adminUsername := strings.TrimSpace(*username)
|
adminUsername := strings.TrimSpace(*username)
|
||||||
if len(adminUsername) < 1 || len(adminUsername) > 64 || strings.ContainsAny(adminUsername, "\r\n\t") {
|
if len(adminUsername) < 1 || len(adminUsername) > 64 || strings.ContainsAny(adminUsername, "\r\n\t") {
|
||||||
|
|||||||
+1
-1
@@ -596,7 +596,7 @@ func (m *menu) msg(key string) string {
|
|||||||
"prompt": {"请选择: ", "Select: "},
|
"prompt": {"请选择: ", "Select: "},
|
||||||
"invalid": {"无效选项,请重试。按 Ctrl+C 退出。", "Invalid choice, try again. Press Ctrl+C to exit."},
|
"invalid": {"无效选项,请重试。按 Ctrl+C 退出。", "Invalid choice, try again. Press Ctrl+C to exit."},
|
||||||
"new_username": {"新用户名(直接回车保留 %s): ", "New username (Enter to keep %s): "},
|
"new_username": {"新用户名(直接回车保留 %s): ", "New username (Enter to keep %s): "},
|
||||||
"new_pw": {"新密码 (至少 12 位): ", "New password (min 12 chars): "},
|
"new_pw": {"新密码 (至少 6 位): ", "New password (min 6 chars): "},
|
||||||
"confirm_pw": {"确认新密码: ", "Confirm new password: "},
|
"confirm_pw": {"确认新密码: ", "Confirm new password: "},
|
||||||
"pw_changed": {"管理员账号密码已修改,现有 Web 会话已退出。", "Administrator credentials changed; existing Web sessions were signed out."},
|
"pw_changed": {"管理员账号密码已修改,现有 Web 会话已退出。", "Administrator credentials changed; existing Web sessions were signed out."},
|
||||||
"current_web_address": {"当前 Web 监听地址: %s", "Current Web listening address: %s"},
|
"current_web_address": {"当前 Web 监听地址: %s", "Current Web listening address: %s"},
|
||||||
|
|||||||
@@ -127,8 +127,8 @@ func (s *Service) ResetAdminCredentials(ctx context.Context, username string, pa
|
|||||||
if len(username) < 1 || len(username) > 64 || strings.ContainsAny(username, "\r\n\t") {
|
if len(username) < 1 || len(username) > 64 || strings.ContainsAny(username, "\r\n\t") {
|
||||||
return errors.New("administrator username must contain between 1 and 64 characters without control whitespace")
|
return errors.New("administrator username must contain between 1 and 64 characters without control whitespace")
|
||||||
}
|
}
|
||||||
if len(password) < 12 || len(password) > 1024 {
|
if len(password) < 6 || len(password) > 1024 {
|
||||||
return errors.New("administrator password must contain between 12 and 1024 characters")
|
return errors.New("administrator password must contain between 6 and 1024 characters")
|
||||||
}
|
}
|
||||||
if err := s.EnsureAdmin(ctx, username, password); err != nil {
|
if err := s.EnsureAdmin(ctx, username, password); err != nil {
|
||||||
return fmt.Errorf("auth: reset administrator credentials: %w", err)
|
return fmt.Errorf("auth: reset administrator credentials: %w", err)
|
||||||
@@ -284,8 +284,8 @@ func (s *Service) ChangePassword(
|
|||||||
currentPassword string,
|
currentPassword string,
|
||||||
newPassword string,
|
newPassword string,
|
||||||
) error {
|
) error {
|
||||||
if len(newPassword) < 12 || len(newPassword) > 1024 {
|
if len(newPassword) < 6 || len(newPassword) > 1024 {
|
||||||
return errors.New("new password must contain between 12 and 1024 characters")
|
return errors.New("new password must contain between 6 and 1024 characters")
|
||||||
}
|
}
|
||||||
admin, err := s.store.AdminByUsername(ctx, strings.TrimSpace(username))
|
admin, err := s.store.AdminByUsername(ctx, strings.TrimSpace(username))
|
||||||
if errors.Is(err, store.ErrNotFound) {
|
if errors.Is(err, store.ErrNotFound) {
|
||||||
|
|||||||
@@ -506,7 +506,7 @@ func (s *Server) handlePasswordChange(w http.ResponseWriter, r *http.Request) {
|
|||||||
switch {
|
switch {
|
||||||
case errors.Is(err, auth.ErrInvalidCredentials):
|
case errors.Is(err, auth.ErrInvalidCredentials):
|
||||||
writeError(w, http.StatusUnauthorized, "invalid_credentials", "current password is incorrect")
|
writeError(w, http.StatusUnauthorized, "invalid_credentials", "current password is incorrect")
|
||||||
case strings.Contains(err.Error(), "between 12 and 1024"):
|
case strings.Contains(err.Error(), "between 6 and 1024"):
|
||||||
writeError(w, http.StatusBadRequest, "weak_password", err.Error())
|
writeError(w, http.StatusBadRequest, "weak_password", err.Error())
|
||||||
case strings.Contains(err.Error(), "must differ"):
|
case strings.Contains(err.Error(), "must differ"):
|
||||||
writeError(w, http.StatusBadRequest, "password_reused", err.Error())
|
writeError(w, http.StatusBadRequest, "password_reused", err.Error())
|
||||||
|
|||||||
Reference in New Issue
Block a user