Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
improve
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Mar 8, 2017
1 parent a862739 commit 2ccd376
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
6 changes: 2 additions & 4 deletions auth.go
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/teambition/gear-auth/jwt"
)

// Version ...
const Version = "1.4.4"

// TokenExtractor is a function that takes a gear.Context as input and
Expand Down Expand Up @@ -120,9 +121,6 @@ func (a *Auth) FromCtx(ctx *gear.Context) (josejwt.Claims, error) {
// app.Use(auther.Serve)
//
func (a *Auth) Serve(ctx *gear.Context) error {
claims, err := a.New(ctx)
if err == nil {
ctx.SetAny(a, claims)
}
_, err := ctx.Any(a)
return err
}
12 changes: 6 additions & 6 deletions crypto/crypto.go
Expand Up @@ -32,10 +32,10 @@ func (c *Crypto) AESKey(a, b string) (key string) {
return base64.RawURLEncoding.EncodeToString(buf)
}

// SignPass returns a string checkPass by the user' name and pass.
func (c *Crypto) SignPass(name, pass string) (checkPass string) {
// SignPass returns a string checkPass by the user' id and pass.
func (c *Crypto) SignPass(id, pass string) (checkPass string) {
iv := RandBytes(8)
b := c.signPass(iv, append(c.HmacSum([]byte(name)), []byte(pass)...))
b := c.signPass(iv, append(c.HmacSum([]byte(id)), []byte(pass)...))
return base64.RawURLEncoding.EncodeToString(b)
}

Expand All @@ -46,13 +46,13 @@ func (c *Crypto) signPass(iv, pass []byte) []byte {
return append(b, iv...)
}

// VerifyPass verify user' name and password with a checkPass(stored in database)
func (c *Crypto) VerifyPass(name, pass, checkPass string) bool {
// VerifyPass verify user' id and password with a checkPass(stored in database)
func (c *Crypto) VerifyPass(id, pass, checkPass string) bool {
a, err := base64.RawURLEncoding.DecodeString(checkPass)
if err != nil {
return false
}
b := c.signPass(a[32:], append(c.HmacSum([]byte(name)), []byte(pass)...))
b := c.signPass(a[32:], append(c.HmacSum([]byte(id)), []byte(pass)...))
return subtle.ConstantTimeCompare(a, b) == 1
}

Expand Down

0 comments on commit 2ccd376

Please sign in to comment.