Passport/pkg/security/factors.go

27 lines
499 B
Go
Raw Normal View History

2024-01-06 17:56:32 +00:00
package security
import (
2024-02-18 03:20:22 +00:00
"code.smartsheep.studio/hydrogen/identity/pkg/models"
2024-01-29 08:11:59 +00:00
"fmt"
2024-01-06 17:56:32 +00:00
"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"),
)
2024-01-29 08:11:59 +00:00
case models.EmailPasswordFactor:
return lo.Ternary(
code == factor.Secret,
nil,
fmt.Errorf("invalid verification code"),
)
2024-01-06 17:56:32 +00:00
}
return nil
}