init from gitlab

This commit is contained in:
texm
2023-04-25 14:33:14 +08:00
parent 6a85a41ff0
commit c8202a5c82
281 changed files with 19861 additions and 1 deletions

View File

@@ -0,0 +1,31 @@
package auth
import (
"golang.org/x/crypto/bcrypt"
)
const DefaultBCryptCost = 14
type PasswordAuthenticator struct {
baseAuthenticator
bcryptCost int
}
func NewPasswordAuthenticator(cfg Config, bCryptCost int) (*PasswordAuthenticator, error) {
pwAuth := &PasswordAuthenticator{}
pwAuth.bcryptCost = bCryptCost
pwAuth.signingKey = cfg.SigningKey
pwAuth.tokenLifetime = cfg.TokenLifetime
pwAuth.cookieDomain = cfg.CookieDomain
pwAuth.authMethod = MethodPassword
return pwAuth, nil
}
func (a *PasswordAuthenticator) HashPassword(password []byte) ([]byte, error) {
return bcrypt.GenerateFromPassword(password, a.bcryptCost)
}
func (a *PasswordAuthenticator) VerifyHash(password []byte, hash []byte) bool {
return bcrypt.CompareHashAndPassword(hash, password) == nil
}