mirror of
https://github.com/yusing/godoxy.git
synced 2026-01-16 23:26:47 +01:00
27 lines
614 B
Go
27 lines
614 B
Go
package rules
|
|
|
|
import (
|
|
httputils "github.com/yusing/goutils/http"
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
type (
|
|
HashedCrendentials struct {
|
|
Username string
|
|
CheckMatch func(inputPwd []byte) bool
|
|
}
|
|
)
|
|
|
|
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 *httputils.Credentials) bool {
|
|
if cred == nil {
|
|
return false
|
|
}
|
|
return hc.Username == cred.Username && hc.CheckMatch(cred.Password)
|
|
}
|