Compare commits

..

No commits in common. "main" and "v1.0.0" have entirely different histories.
main ... v1.0.0

View File

@ -16,20 +16,18 @@ type Passage struct {
valids int valids int
length int length int
pin string pin string
requireEachCharSet bool
} }
func CreatePassage(pin string) *Passage { func CreatePassage(pin string) *Passage {
p := new(Passage) p := new(Passage)
p.length = 20 p.length = 20
p.valids = UseLower | UseUpper | UseNumber | UseSymbol p.valids = UseLower | UseUpper | UseNumber
p.pin = pin p.pin = pin
return p return p
} }
func (p *Passage) SetRequireEachCharSet(r bool) { func (p *Passage) SetPin(pin string) {
p.requireEachCharSet = r p.pin = pin
} }
func (p *Passage) EnableChars(which int) { func (p *Passage) EnableChars(which int) {
@ -40,80 +38,35 @@ func (p *Passage) DisableChars(which int) {
p.valids ^= which p.valids ^= which
} }
func (p *Passage) SetLength(length int) {
p.length = length
}
func (p *Passage) GetLowers() string {
return "abcdefghijklmnopqrstuvwxyz"
}
func (p *Passage) GetUppers() string {
return "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
}
func (p *Passage) GetNumbers() string {
return "1234567890"
}
func (p *Passage) GetSymbols() string {
return "~!@#$%^&*()[]{}|;:,<.>/?"
}
func (p *Passage) GetValidChars() string { func (p *Passage) GetValidChars() string {
validChars := "" validChars := ""
if p.valids&UseLower == UseLower { if p.valids&UseLower == UseLower {
validChars += p.GetLowers() validChars += "abcdefghijklmnopqrstuvwxyz"
} }
if p.valids&UseUpper == UseUpper { if p.valids&UseUpper == UseUpper {
validChars += p.GetUppers() validChars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
} }
if p.valids&UseNumber == UseNumber { if p.valids&UseNumber == UseNumber {
validChars += p.GetNumbers() validChars += "1234567890"
} }
if p.valids&UseSymbol == UseSymbol { if p.valids&UseSymbol == UseSymbol {
validChars += p.GetSymbols() validChars += "~!@#$%^&*()[]{}|;:,<.>/?"
} }
return validChars return validChars
} }
func (p *Passage) GetValidCharSets() []string {
var validChars []string
if p.valids&UseLower == UseLower {
validChars = append(validChars, p.GetLowers())
}
if p.valids&UseUpper == UseUpper {
validChars = append(validChars, p.GetUppers())
}
if p.valids&UseNumber == UseNumber {
validChars = append(validChars, p.GetNumbers())
}
if p.valids&UseSymbol == UseSymbol {
validChars = append(validChars, p.GetSymbols())
}
return validChars
}
func (p *Passage) SetPin(pin string) {
p.pin = pin
}
func (p *Passage) GetPassword(door string) string { func (p *Passage) GetPassword(door string) string {
ret := "" ret := ""
validChars := p.GetValidChars()
hashing := p.pin + " - " + door hashing := p.pin + " - " + door
shaArr := sha256.Sum256([]byte(hashing)) shaArr := sha256.Sum256([]byte(hashing))
var sha []byte var sha []byte
for i := range shaArr { for i := range shaArr {
sha = append(sha, shaArr[i]) sha = append(sha, shaArr[i])
} }
if p.requireEachCharSet {
validChars := p.GetValidCharSets()
for i := 0; i < p.length; i++ {
set := i % len(validChars)
ret += string(validChars[set][int(sha[i])%len(validChars)])
}
} else {
validChars := p.GetValidChars()
for i := 0; i < p.length; i++ { for i := 0; i < p.length; i++ {
ret += string(validChars[int(sha[i])%len(validChars)]) ret += string(validChars[int(sha[i])%len(validChars)])
} }
}
return ret return ret
} }