From f78ccd8d9d45891f2af8550ca096ffaeea78f1da Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Mon, 29 Jan 2024 18:38:19 +0800 Subject: [PATCH] :sparkles: Improve risk calculation --- pkg/security/challanges.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pkg/security/challanges.go b/pkg/security/challanges.go index e1334a5..f396406 100644 --- a/pkg/security/challanges.go +++ b/pkg/security/challanges.go @@ -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,