feat: add generate_otp util

This commit is contained in:
anik-ghosh-au7 2022-07-24 10:40:37 +05:30
parent 480438fb7a
commit ef22318d5c

View File

@ -0,0 +1,24 @@
package utils
import (
"math/rand"
"time"
)
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)))
}