Skip to content

Instantly share code, notes, and snippets.

@muhammadqazi
Created February 6, 2022 11:02
Show Gist options
  • Save muhammadqazi/86ca6bec258c230ec7974a6e2c4d5c84 to your computer and use it in GitHub Desktop.
Save muhammadqazi/86ca6bec258c230ec7974a6e2c4d5c84 to your computer and use it in GitHub Desktop.
Go-Authentication
var table = [...]byte{'1', '2', '3', '4', '5', '6', '7', '8', '9', '0'}
func HandleCodeGenerator(max int) string {
b := make([]byte, max)
n, err := io.ReadAtLeast(rand.Reader, b, max)
if n != max {
panic(err)
}
for i := 0; i < len(b); i++ {
b[i] = table[int(b[i])%len(table)]
}
return string(b)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment