/
githubmirror
/
grafana
Обзор
Документация
Войти
/
githubmirror
/
grafana
Код
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
pkg/api/basic_auth.go
19 строк
678 B
Serge Zaitsev
Macaron: remove custom Request type (#37874)
01 сен 2021, 12:18
Не верифицирован
01 сен 2021, 12:18
c3ab2fd
Код
Авторство
О чём код?
package api import ( "crypto/subtle" "net/http" ) // BasicAuthenticatedRequest parses the provided HTTP request for basic authentication credentials // and returns true if the provided credentials match the expected username and password. // Returns false if the request is unauthenticated. // Uses constant-time comparison in order to mitigate timing attacks. func BasicAuthenticatedRequest(req *http.Request, expectedUser, expectedPass string) bool { user, pass, ok := req.BasicAuth() if !ok || subtle.ConstantTimeCompare([]byte(user), []byte(expectedUser)) != 1 || subtle.ConstantTimeCompare([]byte(pass), []byte(expectedPass)) != 1 { return false } return true }