Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
21
cloud/maplefile-backend/pkg/random/numbers.go
Normal file
21
cloud/maplefile-backend/pkg/random/numbers.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package random
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// GenerateSixDigitCode generates a cryptographically secure random 6-digit number
|
||||
func GenerateSixDigitCode() (string, error) {
|
||||
// Generate a random number between 100000 and 999999
|
||||
max := big.NewInt(900000) // 999999 - 100000 + 1
|
||||
n, err := rand.Int(rand.Reader, max)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
// Add 100000 to ensure 6 digits
|
||||
n.Add(n, big.NewInt(100000))
|
||||
|
||||
return n.String(), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue