all repos — flounder @ 6d4ee53714f7f3d723f18977d5baf458c31fb800

A small site builder for the Gemini protocol

Fix set-password
alex wennerberg alex@alexwennerberg.com
Sat, 09 Jan 2021 23:01:01 -0800
commit

6d4ee53714f7f3d723f18977d5baf458c31fb800

parent

d4db5e2d3c517b27f59adb16486a0043b1f96f85

2 files changed, 12 insertions(+), 3 deletions(-)

jump to
M admin.goadmin.go

@@ -9,6 +9,7 @@

import ( "flag" "fmt" + "golang.org/x/crypto/bcrypt" "golang.org/x/crypto/ssh/terminal" "io/ioutil" "log"

@@ -46,8 +47,9 @@ username := args[2]

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 @@ log.Println("Made admin user", username)

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 }
M main.gomain.go

@@ -48,7 +48,6 @@ }

// load domains in memory refreshDomainMap() - fmt.Println(domains) switch args[0] { case "serve":