Passport/pkg/security/factors.go
2024-02-18 11:21:22 +08:00

27 lines
499 B
Go

package security
import (
"code.smartsheep.studio/hydrogen/identity/pkg/models"
"fmt"
"github.com/samber/lo"
)
func VerifyFactor(factor models.AuthFactor, code string) error {
switch factor.Type {
case models.PasswordAuthFactor:
return lo.Ternary(
VerifyPassword(code, factor.Secret),
nil,
fmt.Errorf("invalid password"),
)
case models.EmailPasswordFactor:
return lo.Ternary(
code == factor.Secret,
nil,
fmt.Errorf("invalid verification code"),
)
}
return nil
}