Skip to content

Commit 4ed43c2

Browse files
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 <me@silverwind.io>
1 parent 9de6594 commit 4ed43c2

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

services/context/captcha.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package context
55

66
import (
77
"fmt"
8+
"image/color"
89
"sync"
910

1011
"code.gitea.io/gitea/modules/cache"
@@ -29,6 +30,15 @@ func GetImageCaptcha() *captcha.Captcha {
2930
imageCaptchaOnce.Do(func() {
3031
cpt = captcha.NewCaptcha(captcha.Options{
3132
SubURL: setting.AppSubURL,
33+
// Use a color palette with high contrast colors suitable for both light and dark modes
34+
// These colors provide good visibility and readability in both themes
35+
ColorPalette: color.Palette{
36+
color.RGBA{R: 234, G: 67, B: 53, A: 255}, // Bright red
37+
color.RGBA{R: 66, G: 133, B: 244, A: 255}, // Medium blue
38+
color.RGBA{R: 52, G: 168, B: 83, A: 255}, // Green
39+
color.RGBA{R: 251, G: 188, B: 5, A: 255}, // Yellow/gold
40+
color.RGBA{R: 171, G: 71, B: 188, A: 255}, // Purple
41+
},
3242
})
3343
cpt.Store = cache.GetCache().ChiCache()
3444
})

0 commit comments

Comments
 (0)