Merge branch 'fixN00bTypo' into 'master'
Fix typo: peeper => pepper See merge request !8
This commit is contained in:
commit
a4cabe7711
@ -38,11 +38,11 @@ type Params struct {
|
|||||||
Backend UserBackend
|
Backend UserBackend
|
||||||
Cookiejar *sessions.CookieStore
|
Cookiejar *sessions.CookieStore
|
||||||
CookieName string
|
CookieName string
|
||||||
Peeper string
|
Pepper string
|
||||||
Cost int
|
Cost int
|
||||||
}
|
}
|
||||||
|
|
||||||
// New Authorizer peeper is like a salt but not stored in database,
|
// New Authorizer pepper is like a salt but not stored in database,
|
||||||
// cost is the bcrypt cost for hashing the password
|
// cost is the bcrypt cost for hashing the password
|
||||||
func New(params Params) *Authorizer {
|
func New(params Params) *Authorizer {
|
||||||
return &Authorizer{
|
return &Authorizer{
|
||||||
@ -52,7 +52,7 @@ func New(params Params) *Authorizer {
|
|||||||
|
|
||||||
// GenHash generates a new hash from a password
|
// GenHash generates a new hash from a password
|
||||||
func (a *Authorizer) GenHash(password string) (string, error) {
|
func (a *Authorizer) GenHash(password string) (string, error) {
|
||||||
b, err := bcrypt.GenerateFromPassword([]byte(password+a.Peeper), a.Cost)
|
b, err := bcrypt.GenerateFromPassword([]byte(password+a.Pepper), a.Cost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
@ -71,7 +71,7 @@ func (a *Authorizer) Login(rw http.ResponseWriter, req *http.Request, username,
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bcrypt.CompareHashAndPassword([]byte(u.GetHash()), []byte(password+a.Peeper))
|
err = bcrypt.CompareHashAndPassword([]byte(u.GetHash()), []byte(password+a.Pepper))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ErrInvalidPassword
|
return ErrInvalidPassword
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
peeper = "polp"
|
pepper = "polp"
|
||||||
ckey = "plop"
|
ckey = "plop"
|
||||||
cookieName = "auth"
|
cookieName = "auth"
|
||||||
cost = 10
|
cost = 10
|
||||||
@ -55,7 +55,7 @@ func getBackend() *Backend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func login(w http.ResponseWriter, r *http.Request) {
|
func login(w http.ResponseWriter, r *http.Request) {
|
||||||
a := New(getBackend(), peeper, cookieName, ckey, cost)
|
a := New(getBackend(), pepper, cookieName, ckey, cost)
|
||||||
err := a.Login(w, r, username, password)
|
err := a.Login(w, r, username, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(w, "%s", err)
|
fmt.Fprintf(w, "%s", err)
|
||||||
@ -66,7 +66,7 @@ func login(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
func logout(w http.ResponseWriter, r *http.Request) {
|
func logout(w http.ResponseWriter, r *http.Request) {
|
||||||
a := New(getBackend(), peeper, cookieName, ckey, cost)
|
a := New(getBackend(), pepper, cookieName, ckey, cost)
|
||||||
err := a.Logout(w, r)
|
err := a.Logout(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(w, "%s", err)
|
fmt.Fprintf(w, "%s", err)
|
||||||
@ -76,7 +76,7 @@ func logout(w http.ResponseWriter, r *http.Request) {
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
}
|
}
|
||||||
func check(w http.ResponseWriter, r *http.Request) {
|
func check(w http.ResponseWriter, r *http.Request) {
|
||||||
a := New(getBackend(), peeper, cookieName, key, cost)
|
a := New(getBackend(), pepper, cookieName, key, cost)
|
||||||
u, err := a.CurrentUser(w, r)
|
u, err := a.CurrentUser(w, r)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
authorizer:
|
authorizer:
|
||||||
cookie_name: auth
|
cookie_name: auth
|
||||||
cookie_key: mysecretkey
|
cookie_key: mysecretkey
|
||||||
peeper: peeper
|
pepper: pepper
|
||||||
cost: 10
|
cost: 10
|
||||||
pgdsn: postgres://test:test@127.0.0.1:5432/dev?sslmode=disable
|
pgdsn: postgres://test:test@127.0.0.1:5432/dev?sslmode=disable
|
||||||
trakttv_client_id: my_trakttv_client_id
|
trakttv_client_id: my_trakttv_client_id
|
||||||
|
@ -17,7 +17,7 @@ type Config struct {
|
|||||||
type AuthorizerConfig struct {
|
type AuthorizerConfig struct {
|
||||||
CookieName string `yaml:"cookie_name"`
|
CookieName string `yaml:"cookie_name"`
|
||||||
Key string `yaml:"cookie_key"`
|
Key string `yaml:"cookie_key"`
|
||||||
Peeper string `yaml:"peeper"`
|
Pepper string `yaml:"pepper"`
|
||||||
Cost int `yaml:"cost"`
|
Cost int `yaml:"cost"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
2
main.go
2
main.go
@ -39,7 +39,7 @@ func main() {
|
|||||||
|
|
||||||
authParams := auth.Params{
|
authParams := auth.Params{
|
||||||
Backend: uBackend,
|
Backend: uBackend,
|
||||||
Peeper: cf.Authorizer.Peeper,
|
Pepper: cf.Authorizer.Pepper,
|
||||||
CookieName: cf.Authorizer.CookieName,
|
CookieName: cf.Authorizer.CookieName,
|
||||||
Cookiejar: sessions.NewCookieStore([]byte(cf.Authorizer.Key)),
|
Cookiejar: sessions.NewCookieStore([]byte(cf.Authorizer.Key)),
|
||||||
Cost: cf.Authorizer.Cost,
|
Cost: cf.Authorizer.Cost,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user