Passport/pkg/security/factors.go

28 lines
494 B
Go
Raw Normal View History

2024-01-06 17:56:32 +00:00
package security
import (
2024-01-29 08:11:59 +00:00
"fmt"
2024-03-20 12:56:43 +00:00
"git.solsynth.dev/hydrogen/identity/pkg/models"
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
}