mirror of
https://github.com/muety/wakapi.git
synced 2023-08-10 21:12:56 +03:00
fix: tests
This commit is contained in:
@ -3,8 +3,6 @@ package utils
|
||||
import (
|
||||
"encoding/base64"
|
||||
"errors"
|
||||
"github.com/gorilla/securecookie"
|
||||
"github.com/muety/wakapi/models"
|
||||
"golang.org/x/crypto/bcrypt"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@ -44,19 +42,6 @@ func ExtractBearerAuth(r *http.Request) (key string, err error) {
|
||||
return string(keyBytes), err
|
||||
}
|
||||
|
||||
func ExtractCookieAuth(r *http.Request, secureCookie *securecookie.SecureCookie) (username *string, err error) {
|
||||
cookie, err := r.Cookie(models.AuthCookieKey)
|
||||
if err != nil {
|
||||
return nil, errors.New("missing authentication")
|
||||
}
|
||||
|
||||
if err := secureCookie.Decode(models.AuthCookieKey, cookie.Value, &username); err != nil {
|
||||
return nil, errors.New("cookie is invalid")
|
||||
}
|
||||
|
||||
return username, nil
|
||||
}
|
||||
|
||||
func CompareBcrypt(wanted, actual, pepper string) bool {
|
||||
plainPassword := []byte(strings.TrimSpace(actual) + pepper)
|
||||
err := bcrypt.CompareHashAndPassword([]byte(wanted), plainPassword)
|
||||
|
Reference in New Issue
Block a user