-x, -f, env vars, prepping for hashing
This commit is contained in:
@@ -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) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user