From 2eea4b27109e6f958a31890844e2bb69fbc21a48 Mon Sep 17 00:00:00 2001 From: "Gabriel A. Giovanini" Date: Mon, 28 Oct 2024 15:58:09 +0100 Subject: feat: Add service to handle auth --- main.go | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 918b794..ab4aee9 100644 --- a/main.go +++ b/main.go @@ -2,8 +2,6 @@ package main import ( "context" - "crypto/rand" - "encoding/base64" "flag" "fmt" "log/slog" @@ -12,7 +10,6 @@ import ( "time" "github.com/alecthomas/chroma/v2/styles" - "golang.org/x/crypto/bcrypt" "git.gabrielgio.me/cerrado/pkg/config" "git.gabrielgio.me/cerrado/pkg/handler" @@ -21,9 +18,6 @@ import ( ) func main() { - ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill) - defer stop() - if len(os.Args) == 4 && os.Args[1] == "hash" { err := hash(os.Args[2], os.Args[3]) if err != nil { @@ -42,36 +36,34 @@ func main() { return } - if err := run(ctx); err != nil { + if err := run(); err != nil { slog.Error("Server", "error", err) os.Exit(1) } } func hash(username string, password string) error { - passphrase := fmt.Sprintf("%s:%s", username, password) - bytes, err := bcrypt.GenerateFromPassword([]byte(passphrase), 14) + hash, err := service.GenerateHash(username, password) if err != nil { return err } - fmt.Println(string(bytes)) + fmt.Println(hash) return nil } func key() error { - key := make([]byte, 64) - - _, err := rand.Read(key) + en, err := service.GenerateAesKey() if err != nil { return err } - - en := base64.StdEncoding.EncodeToString(key) fmt.Println(en) return nil } -func run(ctx context.Context) error { +func run() error { + ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill) + defer stop() + configPath := flag.String("config", "/etc/cerrado.scfg", "File path for the configuration file") flag.Parse() -- cgit v1.2.3