providers: Add crypto provider with bcrypt comparison
This commit is contained in:
parent
3cc005bece
commit
1ec27f18cc
@ -8,6 +8,7 @@ import fppath "git.tebibyte.media/sashakoshka/step/providers/path"
|
||||
import fpmime "git.tebibyte.media/sashakoshka/step/providers/mime"
|
||||
import fpsprig "git.tebibyte.media/sashakoshka/step/providers/sprig"
|
||||
import fpimport "git.tebibyte.media/sashakoshka/step/providers/import"
|
||||
import fpcrypto "git.tebibyte.media/sashakoshka/step/providers/crypto"
|
||||
import fpstrings "git.tebibyte.media/sashakoshka/step/providers/strings"
|
||||
import fpsession "git.tebibyte.media/sashakoshka/step/providers/session"
|
||||
import fpvalidate "git.tebibyte.media/sashakoshka/step/providers/validate"
|
||||
@ -23,6 +24,7 @@ func All () []step.Provider {
|
||||
new(fpmime.Provider),
|
||||
new(fpsprig.Provider),
|
||||
new(fpimport.Provider),
|
||||
new(fpcrypto.Provider),
|
||||
new(fpsession.Provider),
|
||||
new(fpstrings.Provider),
|
||||
new(fpvalidate.Provider),
|
||||
|
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
|
||||
}
|
Loading…
Reference in New Issue
Block a user