feat: hash admin's password before creation
This commit is contained in:
@ -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,
|
||||
})
|
||||
}
|
||||
|
Reference in New Issue
Block a user