mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-05-27 19:19:35 +08:00
feat: add complete MFA support
Add complete MFA support with TOTP, recovery codes, WebAuthn, trusted-device cookie flow, and email/SMS OTP delivery via notification channels. Security follow-up: trusted device tokens are stored in HttpOnly cookies, and SMS OTP reuses the existing Webhook notifier to avoid introducing a new dynamic URL sink.
This commit is contained in:
23
server/internal/security/otp_code.go
Normal file
23
server/internal/security/otp_code.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package security
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const LoginOTPDigits = 6
|
||||
|
||||
func GenerateNumericOTP() (string, error) {
|
||||
limit := big.NewInt(1_000_000)
|
||||
value, err := rand.Int(rand.Reader, limit)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return fmt.Sprintf("%0*d", LoginOTPDigits, value.Int64()), nil
|
||||
}
|
||||
|
||||
func NormalizeNumericOTP(code string) string {
|
||||
return strings.TrimSpace(code)
|
||||
}
|
||||
Reference in New Issue
Block a user