Here's an example function that generates a random password with a custom length and only lowercase letters using Go's built-in crypto/rand
package:
main.go518 chars22 lines
In this example, we define a constant string lowercaseLetters
that contains all the lowercase letters we want to use in our password. Then, we generate a random index between 0 and the length of lowercaseLetters
using crypto/rand
's Int
function. Finally, we append the character at that index to our password string. We repeat this process until we have generated a password of the desired length.
gistlibby LogSnag