From a74e36afc1b42a521ed0be1f3ad250cf839385c8 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Tue, 19 Sep 2023 16:48:29 -0400 Subject: [PATCH] Ajouter basicauth web --- cmd/web.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmd/web.go b/cmd/web.go index 0706774..52d584f 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -4,6 +4,7 @@ Copyright © 2023 AGECEM & Victor Lacasse-Beaudoin package cmd import ( + "crypto/subtle" "fmt" "log" "net/http" @@ -34,6 +35,12 @@ var webCmd = &cobra.Command{ e.Pre(middleware.AddTrailingSlash()) + e.Use(middleware.BasicAuth(func(user, password string, c echo.Context) (bool, error) { + usersMatch := subtle.ConstantTimeCompare([]byte(user), []byte(cfg.Web.User)) == 1 + passwordsMatch := subtle.ConstantTimeCompare([]byte(password), []byte(cfg.Web.Password)) == 1 + return usersMatch && passwordsMatch, nil + })) + client := http.DefaultClient defer client.CloseIdleConnections()