To create a password with a custom length and symbols, you can use Go's cryptography package which provides a strong random generator.
Here's an example code snippet that generates a random string of length n
with a mix of alphabetic and symbolic characters:
main.go178 chars11 lines
You can customize the length of the password by passing a different value to the n
parameter in the RandomString()
function. Additionally, you may remove slash /
and plus +
symbols from the resulting string if your use case does not accept them:
main.go371 chars18 lines
This function produces a password with the specified length without special characters /
and +
.
gistlibby LogSnag