From 55eb4c98623fc35fe973c7aeddbde05b5a318944 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Wed, 21 May 2025 21:17:41 +0200 Subject: [PATCH] feat: hash admin's password before creation --- internal/user/admin.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/user/admin.go b/internal/user/admin.go index 9c9796e..480b12b 100644 --- a/internal/user/admin.go +++ b/internal/user/admin.go @@ -2,10 +2,12 @@ package user import ( "context" + "fmt" "log" "os" "gitea.local/admin/hspguard/internal/repository" + "gitea.local/admin/hspguard/internal/util" "github.com/google/uuid" ) @@ -35,10 +37,16 @@ func EnsureAdminUser(ctx context.Context, repo *repository.Queries) { } func createAdmin(ctx context.Context, name, email, password string, repo *repository.Queries) (uuid.UUID, error) { + hash, err := util.HashPassword(password) + if err != nil { + var id uuid.UUID + return id, fmt.Errorf("failed to hash the admin password") + } + return repo.InsertUser(ctx, repository.InsertUserParams{ FullName: name, Email: email, - PasswordHash: password, + PasswordHash: hash, IsAdmin: true, }) }