A flexible and secure random password generator implemented in Go.
- Customizable password length
- Configurable character set
- Secure random generation using
math/rand
with time-based seeding - Prevents consecutive duplicate characters
- Simple command-line interface
go get github.com/softwareplace/go-password
go run cmd/main.go
Generates a 24-character password using the default character set.
go run cmd/main.go -length=32
Generates a 32-character password.
go run cmd/main.go -chars="ABCDEF123!@#"
Generates a password using only the specified characters.
go run cmd/main.go -help
Displays usage information.
type Generator struct {
Length int // Length of the password to generate
Chars string // Character set to use for generation
}
Sets the password length.
Sets the character set to use.
Generates and returns the password.
Creates a new Generator instance with default values.
Creates a new Generator instance configured via command-line flags.
The default character set includes:
- Lowercase letters:
a-z
- Uppercase letters:
A-Z
- Numbers:
0-9
- Special characters:
!@#$%^&*?
package main
import (
"github.com/softwareplace/go-password/pkg/str"
)
func main() {
// Using defaults
password := str.Default().Generate()
// Custom configuration
customPass := str.New().
SetLength(16).
SetChars("ABCD1234").
Generate()
}
-
Generate a 12-character password:
go run cmd/main.go -length=12
-
Generate a password with only numbers:
go run cmd/main.go -chars="0123456789"
-
Generate a complex 20-character password:
go run cmd/main.go -length=20 -chars="abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789!@#$%^&*?"
- The generator uses Go's
math/rand
package seeded with the current time - For cryptographic applications, consider using
crypto/rand
instead - The implementation prevents consecutive duplicate characters
- Minimum recommended length is 12 characters for basic security
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.