github.com/fanux/shipyard@v0.0.0-20161009071005-6515ce223235/auth/builtin/builtin.go (about) 1 package builtin 2 3 import ( 4 "golang.org/x/crypto/bcrypt" 5 "github.com/shipyard/shipyard/auth" 6 ) 7 8 type ( 9 BuiltinAuthenticator struct { 10 salt []byte 11 } 12 ) 13 14 func NewAuthenticator(salt string) auth.Authenticator { 15 return &BuiltinAuthenticator{ 16 salt: []byte(salt), 17 } 18 } 19 20 func (a BuiltinAuthenticator) IsUpdateSupported() bool { 21 return true 22 } 23 24 func (a BuiltinAuthenticator) Name() string { 25 return "builtin" 26 } 27 28 func (a BuiltinAuthenticator) Authenticate(username, password, hash string) (bool, error) { 29 if err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)); err == nil { 30 return true, nil 31 } 32 return false, nil 33 } 34 35 func (a BuiltinAuthenticator) GenerateToken() (string, error) { 36 return auth.GenerateToken() 37 }