Files
rs_website/tools/genhash/main.go
Blake Ridgway 03fcf37beb first commit
2026-03-07 21:16:51 -06:00

35 lines
755 B
Go

// genhash generates a bcrypt password hash suitable for use as ADMIN_PASSWORD_HASH.
//
// Usage:
//
// go run ./tools/genhash <password>
// make genhash
package main
import (
"fmt"
"os"
"golang.org/x/crypto/bcrypt"
)
func main() {
if len(os.Args) < 2 {
fmt.Fprintln(os.Stderr, "usage: genhash <password>")
fmt.Fprintln(os.Stderr, " or: make genhash")
os.Exit(1)
}
password := os.Args[1]
if len(password) == 0 {
fmt.Fprintln(os.Stderr, "error: password cannot be empty")
os.Exit(1)
}
hash, err := bcrypt.GenerateFromPassword([]byte(password), 12)
if err != nil {
fmt.Fprintln(os.Stderr, "error:", err)
os.Exit(1)
}
fmt.Println(string(hash))
fmt.Fprintln(os.Stderr, "\nSet this as ADMIN_PASSWORD_HASH in your .env file.")
}