Passport/pkg/security/factors.go

32 lines
545 B
Go
Raw Normal View History

2024-01-06 17:56:32 +00:00
package security
import (
"fmt"
"code.smartsheep.studio/hydrogen/passport/pkg/models"
"github.com/samber/lo"
)
2024-01-27 16:05:19 +00:00
func GetFactorCode(factor models.AuthFactor) (bool, error) {
2024-01-06 17:56:32 +00:00
switch factor.Type {
case models.EmailPasswordFactor:
// TODO
2024-01-27 16:05:19 +00:00
return true, nil
2024-01-06 17:56:32 +00:00
default:
2024-01-27 16:05:19 +00:00
return false, nil
2024-01-06 17:56:32 +00:00
}
}
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"),
)
}
return nil
}