mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-27 10:47:06 +02:00
fix proxy rules behavior and implemented a few more rules and commands, dependencies upgrade
This commit is contained in:
27
internal/route/rules/crypto.go
Normal file
27
internal/route/rules/crypto.go
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user