diff options
| author | Rose Hogenson <rosehogenson@posteo.net> | 2025-09-25 22:06:53 -0700 |
|---|---|---|
| committer | Rose Hogenson <rosehogenson@posteo.net> | 2025-09-25 22:06:53 -0700 |
| commit | 08e3307721bebd9416ea6b12eeb3fe464216ef52 (patch) | |
| tree | fdcb1c16bee8d641cf84ae19402f9d2cfb5fa74c | |
| parent | 240e6e995745185c34249f1939d4c0d469a6746e (diff) | |
| download | roseh.moe-08e3307721bebd9416ea6b12eeb3fe464216ef52.tar.zst | |
Make CheckPassword a method
This works better in godoc
| -rw-r--r-- | internal/cryptoutil/cryptoutil.go | 8 | ||||
| -rw-r--r-- | 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) |
