mirror of
https://github.com/yusing/godoxy.git
synced 2025-05-19 20:32:35 +02:00
27 lines
616 B
Go
27 lines
616 B
Go
package rules
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
type (
|
|
HashedCrendentials struct {
|
|
Username string
|
|
CheckMatch func(inputPwd []byte) bool
|
|
}
|
|
Credentials struct {
|
|
Username string
|
|
Password []byte
|
|
}
|
|
)
|
|
|
|
func BCryptCrendentials(username string, hashedPassword []byte) *HashedCrendentials {
|
|
return &HashedCrendentials{username, func(inputPwd []byte) bool {
|
|
return bcrypt.CompareHashAndPassword(hashedPassword, inputPwd) == nil
|
|
}}
|
|
}
|
|
|
|
func (hc *HashedCrendentials) Match(cred *Credentials) bool {
|
|
if cred == nil {
|
|
return false
|
|
}
|
|
return hc.Username == cred.Username && hc.CheckMatch(cred.Password)
|
|
}
|