func CheckSecret(password, secret string) bool {
	compare := compareFuncs[0].compare
	for _, cmp := range compareFuncs[1:] {
		if strings.HasPrefix(secret, cmp.prefix) {
			compare = cmp.compare
			break
		}
	}
	return compare([]byte(secret), []byte(password)) == nil
}
CheckSecret returns true if the password matches the encrypted
secret.
package auth
import (
	"bytes"
	"context"
	"crypto/sha1"
	"crypto/subtle"
	"encoding/base64"
	"errors"
	"net/http"
	"strings"
	"golang.org/x/crypto/bcrypt"
)
type compareFunc func(hashedPassword, password []byte) error
var (
	errMismatchedHashAndPassword = errors.New("mismatched hash and password")
	compareFuncs = []struct {
		prefix  string
		compare compareFunc
	}{
		{"", compareMD5HashAndPassword},  
		{"{SHA}", compareShaHashAndPassword},
		{"$2a$", bcrypt.CompareHashAndPassword},
		{"$2b$", bcrypt.CompareHashAndPassword},
		{"$2x$", bcrypt.CompareHashAndPassword},
		{"$2y$", bcrypt.CompareHashAndPassword},
	}
)
type BasicAuth struct {
	Realm   string
	Secrets SecretProvider
	Headers *Headers
}
var _ = (AuthenticatorInterface)((*BasicAuth)(nil))
func (a *BasicAuth) CheckAuth(r *http.Request) string {
	user, password, ok := r.BasicAuth()
	if !ok {
		return ""
	}
	secret := a.Secrets(user, a.Realm)
	if secret == "" {
		return ""
	}
	if !CheckSecret(password, secret) {
		return ""
	}
	return user
}