-x, -f, env vars, prepping for hashing

This commit is contained in:
2022-05-22 04:43:12 -04:00
parent f76edd3022
commit 1d4d7c5538
15 changed files with 262 additions and 38 deletions

View File

@@ -1,7 +1,9 @@
package pwgenerator
import (
"encoding/xml"
"strings"
"time"
"r00t2.io/goutils/multierr"
)
@@ -44,6 +46,61 @@ func (o *GenOpts) Generate() (passwords []string, err error) {
return
}
/*
GenerateCollection returns a PwCollection instead of a slice of password text.
It contains extended information about a password, hashes, etc.
Note: hashing support currently under construction and not implemented. TODO.
*/
func (o *GenOpts) GenerateCollection(hashAlgos []pwHash) (collection *PwCollection, err error) {
var charset CharSet
var errs *multierr.MultiError = multierr.NewMultiError(nil)
var passwd string
collection = &PwCollection{
XMLName: xml.Name{
Space: "", // TODO?
Local: "collection",
},
Passwords: make([]*PwDef, o.Count),
}
if o.Count == 0 {
o.Count = DefCount
}
if o.LengthMax == 0 {
o.LengthMax = DefMaxLen
}
if err = o.sanChk(); err != nil {
return
}
if charset, err = o.Chars(); err != nil {
return
}
for idx, _ := range collection.Passwords {
if passwd, err = o.generatePassword(charset); err != nil {
errs.AddError(err)
err = nil
}
collection.Passwords[idx] = &PwDef{
XMLName: xml.Name{
Space: "", // TODO?
Local: "password",
},
Password: passwd,
Generated: time.Now(),
Hashes: nil, // TODO
}
}
return
}
// generatePassword generates a single password from CharSet c (plus any minimum requirements).
func (o *GenOpts) generatePassword(c CharSet) (password string, err error) {