providers: Add crypto provider with bcrypt comparison
This commit is contained in:
28
providers/crypto/crypto.go
Normal file
28
providers/crypto/crypto.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package crypto
|
||||
|
||||
import "html/template"
|
||||
import "golang.org/x/crypto/bcrypt"
|
||||
import "git.tebibyte.media/sashakoshka/step"
|
||||
|
||||
var _ step.FuncProvider = new(Provider)
|
||||
|
||||
// Provider provides cryptographic functions.
|
||||
type Provider struct {
|
||||
|
||||
}
|
||||
|
||||
// Package fulfills the step.Provider interface.
|
||||
func (this *Provider) Package () string {
|
||||
return "crypto"
|
||||
}
|
||||
|
||||
// FuncMap fulfills the step.FuncProvider interface.
|
||||
func (this *Provider) FuncMap () template.FuncMap {
|
||||
return template.FuncMap {
|
||||
"bcryptCompare": funcBcryptCompare,
|
||||
}
|
||||
}
|
||||
|
||||
func funcBcryptCompare (hash string, text string) bool {
|
||||
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(text)) == nil
|
||||
}
|
||||
Reference in New Issue
Block a user