@marcel91200 / caddy Mirror · read-only / commits / 76c22c7b
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

auth: Clean up basicauth

Matthew Holt committed Oct 30, 2019 at 13:56 UTC 76c22c7b388d659530a4f6d0ae9f242827f7ed82
2 files changed +6 -26
modules/caddyhttp/caddyauth/basicauth.go
-26
@@ -15,8 +15,6 @@
15 package caddyauth
16
17 import (
18 - "crypto/sha256"
19 - "crypto/subtle"
18 "encoding/json"
19 "fmt"
20 "net/http"
@@ -126,30 +124,6 @@ type Comparer interface {
124 Compare(hashedPassword, plaintextPassword, salt []byte) (bool, error)
125 }
126
129 -type quickComparer struct{}
130 -
131 -func (quickComparer) Compare(theirHash, plaintext, _ []byte) (bool, error) {
132 - ourHash := quickHash(plaintext)
133 - return hashesMatch(ourHash, theirHash), nil
134 -}
135 -
136 -func hashesMatch(pwdHash1, pwdHash2 []byte) bool {
137 - return subtle.ConstantTimeCompare(pwdHash1, pwdHash2) == 1
138 -}
139 -
140 -// quickHash returns the SHA-256 of v. It
141 -// is not secure for password storage, but
142 -// it is useful for efficiently normalizing
143 -// the length of plaintext passwords for
144 -// constant-time comparisons.
145 -//
146 -// Errors are discarded.
147 -func quickHash(v []byte) []byte {
148 - h := sha256.New()
149 - h.Write([]byte(v))
150 - return h.Sum(nil)
151 -}
152 -
127 // Account contains a username, password, and salt (if applicable).
128 type Account struct {
129 Username string `json:"username"`
modules/caddyhttp/caddyauth/hashes.go
+6
@@ -15,6 +15,8 @@
15 package caddyauth
16
17 import (
18 + "crypto/subtle"
19 +
20 "github.com/caddyserver/caddy/v2"
21 "golang.org/x/crypto/bcrypt"
22 "golang.org/x/crypto/scrypt"
@@ -103,6 +105,10 @@ func (s ScryptHash) Compare(hashed, plaintext, salt []byte) (bool, error) {
105 return false, nil
106 }
107
108 +func hashesMatch(pwdHash1, pwdHash2 []byte) bool {
109 + return subtle.ConstantTimeCompare(pwdHash1, pwdHash2) == 1
110 +}
111 +
112 // Interface guards
113 var (
114 _ Comparer = (*BcryptHash)(nil)