mirror of
https://github.com/0xJacky/nginx-ui.git
synced 2025-05-11 02:15:48 +02:00
feat: 2FA authorization for web terminal
This commit is contained in:
parent
802d05f692
commit
3a22861640
15 changed files with 359 additions and 54 deletions
|
@ -4,10 +4,14 @@ import (
|
|||
"bytes"
|
||||
"crypto/sha1"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/0xJacky/Nginx-UI/internal/cache"
|
||||
"github.com/0xJacky/Nginx-UI/internal/crypto"
|
||||
"github.com/0xJacky/Nginx-UI/model"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/pquerna/otp/totp"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -37,3 +41,23 @@ func VerifyOTP(user *model.Auth, otp, recoveryCode string) (err error) {
|
|||
}
|
||||
return
|
||||
}
|
||||
|
||||
func secureSessionIDCacheKey(sessionId string) string {
|
||||
return fmt.Sprintf("otp_secure_session:_%s", sessionId)
|
||||
}
|
||||
|
||||
func SetSecureSessionID(userId int) (sessionId string) {
|
||||
sessionId = uuid.NewString()
|
||||
cache.Set(secureSessionIDCacheKey(sessionId), userId, 5*time.Minute)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func VerifySecureSessionID(sessionId string, userId int) bool {
|
||||
if v, ok := cache.Get(secureSessionIDCacheKey(sessionId)); ok {
|
||||
if v.(int) == userId {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue