6 Commits

Author SHA1 Message Date
Maximilian e4eca321f6 Update version 2023-01-29 23:37:46 -06:00
Maximilian 0eacc92a45 Formatting 2023-01-29 23:36:47 -06:00
Maximilian e96fded8ff Cryptographically generate password characters 2023-01-29 23:30:21 -06:00
max 710f96e9e7 Update binaries to the latest version 2023-01-29 17:44:50 -06:00
max 4609be7a9d Update version 2023-01-29 17:12:49 -06:00
max 57b78dc62e Gracefully handle errors instead of panic 2023-01-29 16:16:44 -06:00
11 changed files with 14 additions and 5 deletions
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
Binary file not shown.
BIN
View File
Binary file not shown.
+14 -5
View File
@@ -1,12 +1,13 @@
// GoPass
// Author: Maximilian Patterson
// Version: 1.2.0
// Version: 1.2.2
package main
import (
cryptorand "crypto/rand"
"encoding/binary"
"fmt"
"math/big"
mathrand "math/rand"
"os"
"strconv"
@@ -18,13 +19,15 @@ func main() {
// Take in all OS arg
args := os.Args[1:]
if len(args) < 1 {
panic("No password length specified! (ex: ./gopass 16)")
println("No password length specified! (ex: ./gopass 16)")
return
}
// Convert String arg to int
size, err := strconv.Atoi(args[0])
if err != nil {
panic("First argument supplied must be an integer! (ex: 16)")
println("First argument supplied must be an integer! (ex: 16)")
return
}
// Grab second argument (if it exists) and use it as a disallowed character(s)
@@ -50,14 +53,20 @@ func main() {
var b [8]byte
_, err = cryptorand.Read(b[:])
if err != nil {
panic("Error securely seeding crypto/rand!")
println("Error securely seeding crypto/rand!")
return
}
mathrand.Seed(int64(binary.LittleEndian.Uint64(b[:])))
// Assign every slot of pass to a random allowedCharacter
for i := range pass {
// Generate a random int greater than 0 and not to exceed the length of allowedCharacters
pass[i] = allowedCharacters[mathrand.Intn(len(allowedCharacters))]
index, err := cryptorand.Int(cryptorand.Reader, big.NewInt(int64(len(allowedCharacters))))
if err != nil {
println("Error securely generating random character!")
return
}
pass[i] = allowedCharacters[index.Int64()]
}
// Print the password