password-generator
is command line interface app to generate random password. This app can be used to generate any random text from provided rules.
Should have go installed. Go can be downloaded from here.
- Clone repo:
git clone git@github.com:shankar524/password-generator.git
cd password-generator
go mod download
- build
go build -o ./pwd-gen .
or
make build
- check if successfully build
./pwd-gen version
- generate random text
- without rules(copies text to clipboard)
./pwd-gen g
- with rules
./pwd-gen g --numbers=7 --symbols=2 --down=2 --up=3 --copy=false
or
./pwd-gen g -n=7 -s=2 -d=2 -u=3 -c=false
- help?
./pwd-gen help
Flag | Short | type | Default value | Meaning |
---|---|---|---|---|
symbol | s | number | 0 | number of symbols to generate in return text |
up | u | number | 4 | number of upper case letters to generate in return text |
down | d | number | 3 | number of down case letters to generate in return text |
number | n | number | 0 | number of numerical digits to generate in return text |
copy | c | boolean | true | copy generated text to clipboard.If set false then prints text in console itself |
This package can also be used as common library to generate random text from provided text rule.
text.TextBuilder
implements text.Builder
interface which include following two function to help build text rule
- AddRule(TextRule) Builder
- Build() (Generator, error)
Also
text.text
implementstext.Generator
interface which allows us to generate text - Generate() string
Sample code usage:
import(
"github.com/shankar524/password-generator/src/text"
)
// create textBuilder
textBuilder := text.TextBuilder{}
textBuilder.AddRule(text.TextRule{For: text.LOWERCASE, Length: 6})
textBuilder.AddRule(text.TextRule{For: text.NUMBER, Length: 2})
textBuilder.AddRule(text.TextRule{For: text.UPPERCASE, Length: 2})
textBuilder.AddRule(text.TextRule{For: text.SYMBOL, Length: 2})
generator, err:= textBuilder.Build()
if err!= nil {
fmt.printf("error creating text generator. Error: %s", err.Error())
return
}
fmt.Print(generator.Generate())
// generate default generator
defaultBuilder := text.TextBuilder{}
defaultGenerator, _ := defaultBuilder.Build()
fmt.Print(defaultGenerator.Generate())