diff options
Diffstat (limited to 'roseh.moe.go')
| -rw-r--r-- | roseh.moe.go | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/roseh.moe.go b/roseh.moe.go index b8e6e21..a15fd9b 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -4,7 +4,6 @@ import ( "bytes" "crypto/ed25519" "crypto/rand" - "crypto/sha512" "crypto/subtle" "embed" "encoding/base64" @@ -19,6 +18,8 @@ import ( "path/filepath" "strings" "time" + + "gitlab.com/rhogenson/roseh.moe/internal/pwhash" ) var ( @@ -30,9 +31,10 @@ var ( ) var ( - notepadPassword []byte - privateKey ed25519.PrivateKey - publicKey ed25519.PublicKey + notepadPassword []byte + notepadPasswordSalt []byte + privateKey ed25519.PrivateKey + publicKey ed25519.PublicKey ) func loadSecrets() error { @@ -56,6 +58,11 @@ func loadSecrets() error { } privateKey = ed25519.NewKeyFromSeed(seed) publicKey = privateKey.Public().(ed25519.PublicKey) + } else if salt, ok := bytes.CutPrefix(line, []byte("salt=")); ok { + notepadPasswordSalt = make([]byte, hex.DecodedLen(len(salt))) + if _, err := hex.Decode(notepadPasswordSalt, salt); err != nil { + return err + } } } return nil @@ -204,7 +211,11 @@ type loginTemplateArgs struct { } func login(w http.ResponseWriter, r *http.Request) { - pwHash := sha512.Sum512([]byte(r.FormValue("password"))) + pwHash, err := pwhash.Hash(r.FormValue("password"), notepadPasswordSalt) + if err != nil { + http.Error(w, fmt.Sprintf("Unable to hash password: %s", err), http.StatusInternalServerError) + return + } if subtle.ConstantTimeCompare(pwHash[:], notepadPassword) == 0 { if err := loginTemplate.Execute(w, loginTemplateArgs{Error: true, Redirect: r.FormValue("redirect")}); err != nil { log.Printf("Warning: login: %s", err) |
