Author Topic: [Go] Random password generator  (Read 1174 times)

0 Members and 1 Guest are viewing this topic.

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
[Go] Random password generator
« on: September 10, 2014, 03:17:20 pm »
This is my version of the random password generator i wrote in C++.
Code: (go) [Select]
package main

import (
"fmt"
"math/rand"
"os"
"strconv"
"time"
)

func main() {
var length int
if len(os.Args) != 2 {
length = 8
} else {
length, _ = strconv.Atoi(os.Args[1])
}
chars := ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()`~-_=+[{]{\\|;:'\",<.>/? ")

rnd := rand.New(rand.NewSource(time.Now().UTC().UnixNano()))//entropy
lenChars := len(chars)
password := make([]byte, length)
for i := 0; i < length; i++ {
password[i] = chars[rnd.Intn(lenChars)]
}
fmt.Println(string(password))
}
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]