From 4ed43c2a32f697ed430b2b3d8755c4839d412632 Mon Sep 17 00:00:00 2001 From: lif <1835304752@qq.com> Date: Sat, 24 Jan 2026 13:41:51 +0800 Subject: [PATCH] fix: Improve image captcha contrast for dark mode (#36265) ## Summary This PR fixes #36255 The image captcha was using random colors which often resulted in poor contrast against dark backgrounds, making it difficult or impossible for users to read in dark mode. ## Changes - Added a custom color palette to the image captcha configuration in `services/context/captcha.go` - The palette uses high-contrast colors (bright red, blue, green, yellow, purple, and dark blue-gray) that provide good visibility in both light and dark themes - This improves accessibility and user experience without changing any existing functionality ## Testing - Builds successfully - All existing tests pass - The color palette is properly supported by the upstream `gitea.com/go-chi/captcha` library --- Generated with Claude Code --------- Signed-off-by: majiayu000 <1835304752@qq.com> Co-authored-by: silverwind --- services/context/captcha.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/services/context/captcha.go b/services/context/captcha.go index 9272e7a65a..b4c3a92907 100644 --- a/services/context/captcha.go +++ b/services/context/captcha.go @@ -5,6 +5,7 @@ package context import ( "fmt" + "image/color" "sync" "code.gitea.io/gitea/modules/cache" @@ -29,6 +30,15 @@ func GetImageCaptcha() *captcha.Captcha { imageCaptchaOnce.Do(func() { cpt = captcha.NewCaptcha(captcha.Options{ SubURL: setting.AppSubURL, + // Use a color palette with high contrast colors suitable for both light and dark modes + // These colors provide good visibility and readability in both themes + ColorPalette: color.Palette{ + color.RGBA{R: 234, G: 67, B: 53, A: 255}, // Bright red + color.RGBA{R: 66, G: 133, B: 244, A: 255}, // Medium blue + color.RGBA{R: 52, G: 168, B: 83, A: 255}, // Green + color.RGBA{R: 251, G: 188, B: 5, A: 255}, // Yellow/gold + color.RGBA{R: 171, G: 71, B: 188, A: 255}, // Purple + }, }) cpt.Store = cache.GetCache().ChiCache() })