diff options
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 24 |
1 files changed, 8 insertions, 16 deletions
@@ -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() |