Skip to content

Commit

Permalink
password sequencer documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Apr 20, 2024
1 parent c012590 commit f0545cd
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions password/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,17 @@ import (
"math/big"
"math/rand/v2"
"sync"
"time"
)

var (
biZero = big.NewInt(0)
biOne = big.NewInt(1)
)

// Sequencer is a deterministic Password Generator that generates all possible
// combinations of passwords for a Charset and defined number of characters in
// the password. It lets you move back and forth through the list of possible
// passwords, and involves no RNG.
type Sequencer interface {
// First moves to the first possible password and returns the same.
First() string
Expand All @@ -37,8 +40,6 @@ type Sequencer interface {
PrevN(n *big.Int) string
// Reset cleans up state and moves to the first possible word.
Reset()
// SetSeed overrides the seed value for the RNG.
SetSeed(seed uint64)
// Stream sends all possible passwords in order to the given channel. If you
// want to limit output, pass in a *big.Int with the number of passwords you
// want to be generated and streamed.
Expand All @@ -65,7 +66,6 @@ type sequencer struct {
// interface.
func NewSequencer(rules ...Rule) (Sequencer, error) {
s := &sequencer{}
s.SetSeed(uint64(time.Now().UnixNano()))
for _, rule := range append(basicRules, rules...) {
rule(s)
}
Expand Down Expand Up @@ -201,14 +201,6 @@ func (s *sequencer) Reset() {
s.First()
}

// SetSeed changes the seed value of the RNG.
func (s *sequencer) SetSeed(seed uint64) {
s.mutex.Lock()
defer s.mutex.Unlock()

s.rng = rand.New(rand.NewPCG(seed, seed+100))
}

// Stream sends all possible passwords in order to the given channel. If you
// want to limit output, pass in a *big.Int with the number of passwords you
// want to be generated and streamed.
Expand Down

0 comments on commit f0545cd

Please sign in to comment.