diff options
-rw-r--r-- | main.go | 28 |
1 files changed, 26 insertions, 2 deletions
@@ -2,6 +2,8 @@ package main import ( "context" + "crypto/rand" + "encoding/base64" "flag" "fmt" "log/slog" @@ -24,14 +26,23 @@ func main() { if len(os.Args) == 4 && os.Args[1] == "hash" { err := hash(os.Args[2], os.Args[3]) if err != nil { - slog.Error("Error", "error", err) + slog.Error("Hash", "error", err) + os.Exit(1) + } + return + } + + if len(os.Args) == 2 && os.Args[1] == "key" { + err := key() + if err != nil { + slog.Error("Key", "error", err) os.Exit(1) } return } if err := run(ctx); err != nil { - slog.Error("Error", "error", err) + slog.Error("Server", "error", err) os.Exit(1) } } @@ -46,6 +57,19 @@ func hash(username string, password string) error { return nil } +func key() error { + key := make([]byte, 64) + + _, err := rand.Read(key) + if err != nil { + return err + } + + en := base64.StdEncoding.EncodeToString(key) + fmt.Println(en) + return nil +} + func run(ctx context.Context) error { var ( configPath = flag.String("config", "/etc/cerrado.scfg", "File path for the configuration file") |