Improve risk calculation

This commit is contained in:
LittleSheep 2024-01-29 18:38:19 +08:00
parent 930607f0f2
commit f78ccd8d9d

View File

@ -2,7 +2,6 @@ package security
import (
"fmt"
"math"
"time"
"code.smartsheep.studio/hydrogen/passport/pkg/database"
@ -36,7 +35,7 @@ func NewChallenge(account models.Account, factors []models.AuthFactor, ip, ua st
}
// Thinking of the requirements factors
requirements := int(math.Max(float64(len(factors)), math.Min(float64(risk), 1)))
requirements := lo.Clamp(risk, 1, len(factors))
challenge = models.AuthChallenge{
IpAddress: ip,