Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions internal/crypto/crypto.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ import (

// GenerateOtp generates a random n digit otp
func GenerateOtp(digits int) string {
upper := math.Pow10(digits)
val := must(rand.Int(rand.Reader, big.NewInt(int64(upper))))

// adds a variable zero-padding to the left to ensure otp is uniformly random
expr := "%0" + strconv.Itoa(digits) + "v"
otp := fmt.Sprintf(expr, val.String())

return otp
upper := math.Pow10(digits)
val := must(rand.Int(rand.Reader, big.NewInt(int64(upper))))
s := val.String()
if len(s) < digits {
s = strings.Repeat("0", digits-len(s)) + s
}
return s
}

func GenerateTokenHash(emailOrPhone, otp string) string {
Expand Down