From 08e3307721bebd9416ea6b12eeb3fe464216ef52 Mon Sep 17 00:00:00 2001 From: Rose Hogenson Date: Thu, 25 Sep 2025 22:06:53 -0700 Subject: Make CheckPassword a method This works better in godoc --- internal/cryptoutil/cryptoutil.go | 8 ++++---- roseh.moe.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/cryptoutil/cryptoutil.go b/internal/cryptoutil/cryptoutil.go index c5d2a86..b58282b 100644 --- a/internal/cryptoutil/cryptoutil.go +++ b/internal/cryptoutil/cryptoutil.go @@ -62,7 +62,7 @@ type EncryptionKey []byte // An EncryptedMessage is encrypted with AES-256-CTR-HMAC-SHA256. type EncryptedMessage []byte -// HashIter runs pbkdf2-sha256 for iter iterations. Useful for benchmarking. +// HashIter runs PBKDF2-SHA256 for iter iterations. Useful for benchmarking. func HashIter(password string, salt []byte, iter int) ([]byte, error) { return pbkdf2.Key(sha256.New, password, salt, iter, sha256.Size) } @@ -94,10 +94,10 @@ func Hash(password string) (PasswordHash, error) { return append(salt, pwHash...), nil } -// CheckPassword verifies password against expectedHash and returns an +// CheckPassword verifies password against a PasswordHash and returns an // EncryptionKey derived from the password if successful. -func CheckPassword(password string, expectedHash PasswordHash) (RawKey, error) { - salt, expectedHash := expectedHash[:saltSize], expectedHash[saltSize:] +func (h PasswordHash) CheckPassword(password string) (RawKey, error) { + salt, expectedHash := h[:saltSize], h[saltSize:] key, pwHash, err := hashWithSalt(password, salt) if err != nil { return RawKey{}, err diff --git a/roseh.moe.go b/roseh.moe.go index 6624706..e38677d 100644 --- a/roseh.moe.go +++ b/roseh.moe.go @@ -205,7 +205,7 @@ type loginTemplateArgs struct { } func login(w http.ResponseWriter, r *http.Request) { - rawKey, err := cryptoutil.CheckPassword(r.FormValue("password"), notepadPassword) + rawKey, err := notepadPassword.CheckPassword(r.FormValue("password")) if err != nil { if err := loginTemplate.Execute(w, loginTemplateArgs{Error: true}); err != nil { log.Printf("Warning: login: %s", err) -- cgit v1.3.1