GoPass/main.go

49 lines
1.1 KiB
Go
Raw Normal View History

2022-08-02 23:07:28 +00:00
// GoPass
// Author: Maximilian Patterson
2022-12-19 16:21:06 +00:00
// Version: 1.2
2022-08-02 23:07:28 +00:00
package main
2022-08-02 22:37:06 +00:00
import (
2022-10-09 20:57:01 +00:00
cryptorand "crypto/rand"
"encoding/binary"
2022-08-02 22:37:06 +00:00
"fmt"
2022-10-09 20:57:01 +00:00
mathrand "math/rand"
2022-08-02 22:37:06 +00:00
"os"
"strconv"
)
var runes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()_+[]\\{}|;':,./<>?")
func main() {
2022-12-19 16:21:06 +00:00
// Take OS arg (only accepts one arg) handle errors
args := os.Args[1:]
if len(args) != 1 {
panic("No password length specified! (ex: ./gopass 16)")
}
2022-08-02 22:37:06 +00:00
// Convert String arg to int
2022-12-19 16:21:06 +00:00
size, err := strconv.Atoi(args[0])
2022-08-02 22:37:06 +00:00
if err != nil {
2022-12-19 16:21:06 +00:00
panic("Argument supplied must be an integer! (ex: 16)")
2022-08-02 22:37:06 +00:00
}
// Make empty array of runes with size of size
pass := make([]rune, size)
// Seed rand with time
2022-10-09 20:57:01 +00:00
var b [8]byte
_, err = cryptorand.Read(b[:])
if err != nil {
2022-12-19 16:21:06 +00:00
panic("Error securely seeding crypto/rand!")
2022-10-09 20:57:01 +00:00
}
mathrand.Seed(int64(binary.LittleEndian.Uint64(b[:])))
2022-08-02 22:37:06 +00:00
// Assign every slot of pass to a random rune (generate rand int of length runes to select)
for i := range pass {
2022-10-09 20:57:01 +00:00
pass[i] = runes[mathrand.Intn(len(runes))]
2022-08-02 22:37:06 +00:00
}
// Print the pass :D
fmt.Println(string(pass))
}