Skip to content

Instantly share code, notes, and snippets.

@bigmeech
Last active March 21, 2017 20:24
Show Gist options
  • Select an option

  • Save bigmeech/ec56b56113935085d176e8d5ad6e7f44 to your computer and use it in GitHub Desktop.

Select an option

Save bigmeech/ec56b56113935085d176e8d5ad6e7f44 to your computer and use it in GitHub Desktop.
gen pass
package main
import (
"fmt"
"math/rand"
"time"
"flag"
)
func getRandomStrings(str_len int) string {
const str_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&$|#@*_"
rand.Seed(time.Now().UTC().UnixNano());
data := make([]byte, str_len);
for i := 0; i < str_len; i++ {
data[i] = str_chars[rand.Intn(len(str_chars))];
}
return string(data)
}
func generatePassword(vargs ...interface{}) string {
if len(vargs) > 0 && vargs[0].(string) != "" {
return vargs[0].(string) + "SALT"
}
return getRandomStrings(10) + "SALT";
}
func main() {
password := flag.String("p", "", "optional password")
flag.Parse()
pass := generatePassword(*password)
fmt.Println(pass)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment