Symbols are usable

(but disabled by default, for my own backwards compatibility)
This commit is contained in:
Brian Buller 2017-01-25 12:06:19 -06:00
parent f37377dd63
commit ea879bd57e

View File

@ -21,7 +21,7 @@ type Passage struct {
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
} }
@ -30,8 +30,15 @@ func (p *Passage) SetPin(pin string) {
p.pin = pin p.pin = pin
} }
func (p *Passage) GetPassword(door string) string { func (p *Passage) EnableChars(which int) {
ret := "" p.valids |= which
}
func (p *Passage) DisableChars(which int) {
p.valids ^= which
}
func (p *Passage) GetValidChars() string {
validChars := "" validChars := ""
if p.valids&UseLower == UseLower { if p.valids&UseLower == UseLower {
validChars += "abcdefghijklmnopqrstuvwxyz" validChars += "abcdefghijklmnopqrstuvwxyz"
@ -42,6 +49,15 @@ func (p *Passage) GetPassword(door string) string {
if p.valids&UseNumber == UseNumber { if p.valids&UseNumber == UseNumber {
validChars += "1234567890" validChars += "1234567890"
} }
if p.valids&UseSymbol == UseSymbol {
validChars += "~!@#$%^&*()[]{}|;:,<.>/?"
}
return validChars
}
func (p *Passage) GetPassword(door string) string {
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
@ -49,7 +65,6 @@ func (p *Passage) GetPassword(door string) string {
sha = append(sha, shaArr[i]) sha = append(sha, shaArr[i])
} }
for i := 0; i < p.length; i++ { for i := 0; i < p.length; i++ {
//for i := range sha {
ret += string(validChars[int(sha[i])%len(validChars)]) ret += string(validChars[int(sha[i])%len(validChars)])
} }
return ret return ret