flounder

A simple gemini site builder
Log | Files | Refs | README | LICENSE

commit 6d4ee53714f7f3d723f18977d5baf458c31fb800
parent d4db5e2d3c517b27f59adb16486a0043b1f96f85
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sat,  9 Jan 2021 23:01:01 -0800

Fix set-password

Diffstat:
Madmin.go | 14++++++++++++--
Mmain.go | 1-
2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/admin.go b/admin.go @@ -9,6 +9,7 @@ package main import ( "flag" "fmt" + "golang.org/x/crypto/bcrypt" "golang.org/x/crypto/ssh/terminal" "io/ioutil" "log" @@ -46,8 +47,9 @@ func runAdminCommand() { fmt.Print("Enter New Password: ") bytePassword, err := terminal.ReadPassword(int(syscall.Stdin)) if err != nil { - setPassword(username, bytePassword) + log.Fatal(err) } + err = setPassword(username, bytePassword) } if err != nil { log.Fatal(err) @@ -65,7 +67,15 @@ func makeAdmin(username string) error { return nil } -func setPassword(username string, newPass []byte) error { +func setPassword(username string, newPass []byte) error { // TODO rm code dup + hashedPassword, err := bcrypt.GenerateFromPassword(newPass, 8) + if err != nil { + return err + } + _, err = DB.Exec("UPDATE user SET password_hash = ? WHERE username = ?", hashedPassword, username) + if err != nil { + return err + } return nil } diff --git a/main.go b/main.go @@ -48,7 +48,6 @@ func main() { // load domains in memory refreshDomainMap() - fmt.Println(domains) switch args[0] { case "serve":