26 lines
490 B
Go
26 lines
490 B
Go
package utils
|
|
|
|
import (
|
|
"math/rand"
|
|
"time"
|
|
)
|
|
|
|
// GenerateOTP to generate random 6 digit otp
|
|
func GenerateOTP() string {
|
|
code := ""
|
|
codeLength := 6
|
|
charSet := "ABCDEFGHJKLMNPQRSTUVWXYZ123456789"
|
|
charSetLength := int32(len(charSet))
|
|
for i := 0; i < codeLength; i++ {
|
|
index := randomNumber(0, charSetLength)
|
|
code += string(charSet[index])
|
|
}
|
|
|
|
return code
|
|
}
|
|
|
|
func randomNumber(min, max int32) int32 {
|
|
rand.Seed(time.Now().UnixNano())
|
|
return min + int32(rand.Intn(int(max-min)))
|
|
}
|