Created
September 16, 2019 18:46
-
-
Save sergkondr/736df7df3b25428a2256ca3a777842b6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"flag" | |
"fmt" | |
"math/rand" | |
"time" | |
) | |
var ( | |
passwordLength int | |
useSymbols bool | |
letterRunes = []rune("1234567890ABCDEFGHJKLMNPQRSTUVWXYZghjkmnpqrstuvwxy") | |
symbolRunes = []rune("!@#$&?") | |
) | |
func init() { | |
flag.IntVar(&passwordLength, "length", 12, "-len 12, -l 12") | |
flag.IntVar(&passwordLength, "l", 12, "") | |
flag.BoolVar(&useSymbols, "symbols", false, "use additional symbols: [!@#$&?]") | |
flag.BoolVar(&useSymbols, "s", false, "") | |
flag.Parse() | |
if useSymbols { | |
letterRunes = append(letterRunes, symbolRunes...) | |
} | |
rand.Seed(time.Now().UnixNano()) | |
} | |
func main() { | |
fmt.Println(getRandString(passwordLength)) | |
} | |
func getRandString(l int) string { | |
b := make([]rune, l) | |
for i := range b { | |
b[i] = letterRunes[rand.Intn(len(letterRunes))] | |
} | |
return string(b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment