mirror of
https://github.com/Awuqing/BackupX.git
synced 2026-06-22 10:03:39 +08:00
24 lines
406 B
Go
24 lines
406 B
Go
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)
|
|
}
|