mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 04:10:20 +08:00
Add MfaTotpPeriodInSeconds param
This commit is contained in:
@ -17,6 +17,7 @@ package object
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego"
|
"github.com/beego/beego"
|
||||||
"github.com/beego/beego/context"
|
"github.com/beego/beego/context"
|
||||||
@ -25,7 +26,10 @@ import (
|
|||||||
"github.com/pquerna/otp/totp"
|
"github.com/pquerna/otp/totp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MfaTotpSecretSession = "mfa_totp_secret"
|
const (
|
||||||
|
MfaTotpSecretSession = "mfa_totp_secret"
|
||||||
|
MfaTotpPeriodInSeconds = 30
|
||||||
|
)
|
||||||
|
|
||||||
type TotpMfa struct {
|
type TotpMfa struct {
|
||||||
Config *MfaProps
|
Config *MfaProps
|
||||||
@ -76,7 +80,13 @@ func (mfa *TotpMfa) SetupVerify(ctx *context.Context, passcode string) error {
|
|||||||
if secret == nil {
|
if secret == nil {
|
||||||
return errors.New("totp secret is missing")
|
return errors.New("totp secret is missing")
|
||||||
}
|
}
|
||||||
result := totp.Validate(passcode, secret.(string))
|
|
||||||
|
result, _ := totp.ValidateCustom(passcode, secret.(string), time.Now().UTC(), totp.ValidateOpts{
|
||||||
|
Period: MfaTotpPeriodInSeconds,
|
||||||
|
Skew: 1,
|
||||||
|
Digits: otp.DigitsSix,
|
||||||
|
Algorithm: otp.AlgorithmSHA1,
|
||||||
|
})
|
||||||
|
|
||||||
if result {
|
if result {
|
||||||
return nil
|
return nil
|
||||||
@ -133,7 +143,7 @@ func NewTotpMfaUtil(config *MfaProps) *TotpMfa {
|
|||||||
|
|
||||||
return &TotpMfa{
|
return &TotpMfa{
|
||||||
Config: config,
|
Config: config,
|
||||||
period: 30,
|
period: MfaTotpPeriodInSeconds,
|
||||||
secretSize: 20,
|
secretSize: 20,
|
||||||
digits: otp.DigitsSix,
|
digits: otp.DigitsSix,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user