feat: hash admin's password before creation

This commit is contained in:
2025-05-21 21:17:41 +02:00
parent de28470432
commit 55eb4c9862

View File

@ -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,
})
}