providers: Add crypto provider with bcrypt comparison

This commit is contained in:
2024-12-14 02:21:43 -05:00
parent 3cc005bece
commit 1ec27f18cc
2 changed files with 30 additions and 0 deletions

View 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
}