Compare commits
34 Commits
3f1cbdc9a7
...
v1.3.0
Author | SHA1 | Date | |
---|---|---|---|
bb4dda5d9f | |||
14b7b1d181 | |||
83c7065d2a | |||
3978c9ad47 | |||
e1ced3f76d | |||
cdbca3b074 | |||
e4eca321f6 | |||
0eacc92a45 | |||
e96fded8ff | |||
710f96e9e7 | |||
4609be7a9d | |||
57b78dc62e | |||
87fa1107d7 | |||
3915761477 | |||
5ba592db21 | |||
b81783b470 | |||
cebcbc2823 | |||
b5b7c208f2 | |||
8aa2f61b3c | |||
f2a9cdd216 | |||
c99539c0a9 | |||
33cf6cde39 | |||
8114d2a6c9 | |||
7b36f39de6 | |||
564da340d5 | |||
9e3549f57d | |||
e72f27f80c | |||
1bc20536b5 | |||
03b6ac8375 | |||
388d56b697 | |||
0c3198536f | |||
b1ddefb847 | |||
bbfcf4d5f0 | |||
4dd661572b |
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@
|
|||||||
# Go workspace file
|
# Go workspace file
|
||||||
go.work
|
go.work
|
||||||
|
|
||||||
|
/.idea/
|
37
README.md
37
README.md
@ -1,9 +1,38 @@
|
|||||||
# GoPass
|
# GoPass
|
||||||
|
|
||||||
An easy to use command-line password generator that creates secure passwords
|
An easy to use command-line password generator that creates secure passwords
|
||||||
|
|
||||||
# Usage:
|
# Usage:
|
||||||
<code>./gopass [number of characters]</code><br>
|
|
||||||
|
`./gopass [number of characters]`<br>
|
||||||
|
or <br>
|
||||||
|
`./gopass [number of characters] -r=[excluded characters] [-s to remove all symbols]`
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
eg:
|
|
||||||
<code>./gopass 32</code><br>
|
eg: `./gopass 32` <br>
|
||||||
output: <code>E$bGOiiPASS*,ISl{!MJ&<\[COOL0eVw</code>
|
output: `E$bGOiiPASS*,ISl{!MJ&<\[COOL0eVw` <br>
|
||||||
|
eg: (with excluded characters): `./gopass 32 -r=$,!` <br>
|
||||||
|
output: `EYbGOiiPASS*2ISl{?MJ&<\[COOL0eVw` <- note the excluded characters are not present in the output <br>
|
||||||
|
eg: `./gopass 32 -s` <br>
|
||||||
|
output: `LEYbGOiiPASS2ISlMJCOOL0eRt3KPOVw` <- note the symbols are not present in the output <br>
|
||||||
|
eg: `./gopass 32 -r=$,! -s` the -r and -s flags can be combined <br>
|
||||||
|
|
||||||
|
# How to install/use for Windows:
|
||||||
|
|
||||||
|
1. Download Windows binary, it may be helpful to simply rename it to "gopass.exe" (make sure to add .exe, this won't
|
||||||
|
need to
|
||||||
|
be typed to execute the file from the CLI, but it is required for Windows to recognize the binary) to keep
|
||||||
|
commands shorter.
|
||||||
|
2. Move the file to your `C:\Users\[Username]` directory
|
||||||
|
3. Opening the console *without* Administrator privileges will put you in the directory mentioned above by default
|
||||||
|
4. Now type `gopass [number of characters]` (Ex. `gopass 64`) to generate a new password!
|
||||||
|
|
||||||
|
# How to install/use for Linux:
|
||||||
|
|
||||||
|
1. Download Linux binary, it may be helpful to simply rename it to "gopass" to keep commands shorter.
|
||||||
|
2. Move the file to your home directory.
|
||||||
|
3. `chmod +x gopass` if necessary
|
||||||
|
3. Opening your terminal should put you in your home directory by default, if not, just type `cd` to get sent back to
|
||||||
|
home.
|
||||||
|
4. Now type `./gopass [number of characters]` (Ex. `./gopass 64`) to generate a new password!
|
BIN
bin/gopass-darwin-amd64-1.3.0
Executable file
BIN
bin/gopass-darwin-amd64-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-freebsd-386-1.3.0
Executable file
BIN
bin/gopass-freebsd-386-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-freebsd-amd64-1.3.0
Executable file
BIN
bin/gopass-freebsd-amd64-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-freebsd-arm-1.3.0
Executable file
BIN
bin/gopass-freebsd-arm-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-linux-386-1.3.0
Executable file
BIN
bin/gopass-linux-386-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-linux-amd64-1.3.0
Executable file
BIN
bin/gopass-linux-amd64-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-linux-arm-1.3.0
Executable file
BIN
bin/gopass-linux-arm-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-plan9-386-1.3.0
Executable file
BIN
bin/gopass-plan9-386-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-plan9-amd64-1.3.0
Executable file
BIN
bin/gopass-plan9-amd64-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-plan9-arm-1.3.0
Executable file
BIN
bin/gopass-plan9-arm-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-windows-386-1.3.0
Executable file
BIN
bin/gopass-windows-386-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-windows-amd64-1.3.0
Executable file
BIN
bin/gopass-windows-amd64-1.3.0
Executable file
Binary file not shown.
BIN
bin/gopass-windows-arm-1.3.0
Executable file
BIN
bin/gopass-windows-arm-1.3.0
Executable file
Binary file not shown.
94
main.go
94
main.go
@ -1,36 +1,94 @@
|
|||||||
package GoPass
|
// GoPass
|
||||||
|
// Author: Maximilian Patterson
|
||||||
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
var runes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()_+[]\\{}|;':,./<>?")
|
var allowedCharacters = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890`~!@#$%^&*()_+[]\\{}|;':,./<>?")
|
||||||
|
|
||||||
func main() {
|
const (
|
||||||
// Take OS arg (only accepts one arg)
|
Version = "1.3.0"
|
||||||
arg := os.Args[1]
|
symbols = "`~!@#$%^&*()_+[]\\{}|;':,./<>?"
|
||||||
|
)
|
||||||
|
|
||||||
// Convert String arg to int
|
func matchArguments(args []string) string {
|
||||||
size, err := strconv.Atoi(arg)
|
// If there are no arguments
|
||||||
if err != nil {
|
if len(args) == 0 {
|
||||||
panic(err)
|
return "No password length specified! (ex: gopass 16)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// First argument is special, must be an integer, -v, or -h
|
||||||
|
var size = 0 // Password length
|
||||||
|
err := error(nil)
|
||||||
|
if size, err = strconv.Atoi(args[0]); err == nil { // If first argument is an integer
|
||||||
|
} else if args[0] == "-v" {
|
||||||
|
return "GoPass version " + Version
|
||||||
|
} else if args[0] == "-h" {
|
||||||
|
return "GoPass - A simple password generator written in Go\n" +
|
||||||
|
"Usage: gopass [length] [disallowed characters] [optional remove symbols -s]\n" +
|
||||||
|
" Example: gopass 16\n" +
|
||||||
|
" Example: gopass 16 -r=abc123!@#\n" +
|
||||||
|
" Example: gopass 16 -s\n" +
|
||||||
|
"\nFor help (this output): gopass -h\n" +
|
||||||
|
"For version: gopass -v\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
for i := 1; i < len(args); i++ {
|
||||||
|
v := args[i]
|
||||||
|
if v == "-s" {
|
||||||
|
removeDisallowed([]rune(symbols))
|
||||||
|
} else if strings.HasPrefix(v, "-r=") { // If argument starts with -r=
|
||||||
|
// Remove all characters after the = until next whitespace
|
||||||
|
removeDisallowed([]rune(v[2:]))
|
||||||
|
} else {
|
||||||
|
return "Invalid argument (\"" + v + "\") supplied! (Type gopass -h for help)"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if size <= 0 {
|
||||||
|
return "No/invalid password length specified! (ex: gopass 16)"
|
||||||
|
} else {
|
||||||
|
return generatePassword(size)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all disallowed characters from the allowedCharacters slice
|
||||||
|
func removeDisallowed(disallowed []rune) {
|
||||||
|
for _, r := range disallowed {
|
||||||
|
for i, v := range allowedCharacters {
|
||||||
|
if v == r {
|
||||||
|
allowedCharacters = append(allowedCharacters[:i], allowedCharacters[i+1:]...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func generatePassword(size int) string {
|
||||||
// Make empty array of runes with size of size
|
// Make empty array of runes with size of size
|
||||||
pass := make([]rune, size)
|
pass := make([]rune, size)
|
||||||
|
|
||||||
// Seed rand with time
|
// Assign every slot of pass to a random allowedCharacter
|
||||||
rand.Seed(time.Now().UTC().UnixNano())
|
|
||||||
|
|
||||||
// Assign every slot of pass to a random rune (generate rand int of length runes to select)
|
|
||||||
for i := range pass {
|
for i := range pass {
|
||||||
pass[i] = runes[rand.Intn(len(runes))]
|
// Generate a random int greater than 0 and not to exceed the length of allowedCharacters
|
||||||
|
index, err := rand.Int(rand.Reader, big.NewInt(int64(len(allowedCharacters))))
|
||||||
|
if err != nil {
|
||||||
|
println("Error securely generating random character!")
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
pass[i] = allowedCharacters[index.Int64()]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print the pass :D
|
return string(pass)
|
||||||
fmt.Println(string(pass))
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Process arguments
|
||||||
|
fmt.Println(matchArguments(os.Args[1:]))
|
||||||
}
|
}
|
||||||
|
87
makefile
Normal file
87
makefile
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
# The current version number of the program
|
||||||
|
VERSION := 1.3.0
|
||||||
|
|
||||||
|
# List of OS and architecture combinations to build
|
||||||
|
BUILD_OS_ARCH := \
|
||||||
|
darwin/amd64 \
|
||||||
|
freebsd/386 \
|
||||||
|
freebsd/amd64 \
|
||||||
|
freebsd/arm \
|
||||||
|
linux/386 \
|
||||||
|
linux/amd64 \
|
||||||
|
linux/arm \
|
||||||
|
plan9/386 \
|
||||||
|
plan9/amd64 \
|
||||||
|
plan9/arm \
|
||||||
|
windows/386 \
|
||||||
|
windows/amd64 \
|
||||||
|
windows/arm
|
||||||
|
|
||||||
|
# Build all targets
|
||||||
|
all: $(BUILD_OS_ARCH)
|
||||||
|
|
||||||
|
# Build targets in the form of `OS/ARCH`
|
||||||
|
darwin/amd64:
|
||||||
|
GOOS=darwin \
|
||||||
|
GOARCH=amd64 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-darwin-amd64-$(VERSION)" main.go
|
||||||
|
|
||||||
|
freebsd/386:
|
||||||
|
GOOS=freebsd \
|
||||||
|
GOARCH=386 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-freebsd-386-$(VERSION)" main.go
|
||||||
|
|
||||||
|
freebsd/amd64:
|
||||||
|
GOOS=freebsd \
|
||||||
|
GOARCH=amd64 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-freebsd-amd64-$(VERSION)" main.go
|
||||||
|
|
||||||
|
freebsd/arm:
|
||||||
|
GOOS=freebsd \
|
||||||
|
GOARCH=arm \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-freebsd-arm-$(VERSION)" main.go
|
||||||
|
|
||||||
|
linux/386:
|
||||||
|
GOOS=linux \
|
||||||
|
GOARCH=386 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-linux-386-$(VERSION)" main.go
|
||||||
|
|
||||||
|
linux/amd64:
|
||||||
|
GOOS=linux \
|
||||||
|
GOARCH=amd64 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-linux-amd64-$(VERSION)" main.go
|
||||||
|
|
||||||
|
linux/arm:
|
||||||
|
GOOS=linux \
|
||||||
|
GOARCH=arm \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-linux-arm-$(VERSION)" main.go
|
||||||
|
|
||||||
|
plan9/386:
|
||||||
|
GOOS=plan9 \
|
||||||
|
GOARCH=386 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-plan9-386-$(VERSION)" main.go
|
||||||
|
|
||||||
|
plan9/amd64:
|
||||||
|
GOOS=plan9 \
|
||||||
|
GOARCH=amd64 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-plan9-amd64-$(VERSION)" main.go
|
||||||
|
|
||||||
|
plan9/arm:
|
||||||
|
GOOS=plan9 \
|
||||||
|
GOARCH=arm \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-plan9-arm-$(VERSION)" main.go
|
||||||
|
|
||||||
|
windows/386:
|
||||||
|
GOOS=windows \
|
||||||
|
GOARCH=386 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-windows-386-$(VERSION)" main.go
|
||||||
|
|
||||||
|
windows/amd64:
|
||||||
|
GOOS=windows \
|
||||||
|
GOARCH=amd64 \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-windows-amd64-$(VERSION)" main.go
|
||||||
|
|
||||||
|
windows/arm:
|
||||||
|
GOOS=windows \
|
||||||
|
GOARCH=arm \
|
||||||
|
go build -ldflags="-s -w" -o "gopass-windows-arm-$(VERSION)" main.go
|
Reference in New Issue
Block a user