Symbols are usable
(but disabled by default, for my own backwards compatibility)
This commit is contained in:
parent
f37377dd63
commit
ea879bd57e
23
passage.go
23
passage.go
@ -21,7 +21,7 @@ type Passage struct {
|
||||
func CreatePassage(pin string) *Passage {
|
||||
p := new(Passage)
|
||||
p.length = 20
|
||||
p.valids = UseLower | UseUpper | UseNumber | UseSymbol
|
||||
p.valids = UseLower | UseUpper | UseNumber
|
||||
p.pin = pin
|
||||
return p
|
||||
}
|
||||
@ -30,8 +30,15 @@ func (p *Passage) SetPin(pin string) {
|
||||
p.pin = pin
|
||||
}
|
||||
|
||||
func (p *Passage) GetPassword(door string) string {
|
||||
ret := ""
|
||||
func (p *Passage) EnableChars(which int) {
|
||||
p.valids |= which
|
||||
}
|
||||
|
||||
func (p *Passage) DisableChars(which int) {
|
||||
p.valids ^= which
|
||||
}
|
||||
|
||||
func (p *Passage) GetValidChars() string {
|
||||
validChars := ""
|
||||
if p.valids&UseLower == UseLower {
|
||||
validChars += "abcdefghijklmnopqrstuvwxyz"
|
||||
@ -42,6 +49,15 @@ func (p *Passage) GetPassword(door string) string {
|
||||
if p.valids&UseNumber == UseNumber {
|
||||
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
|
||||
shaArr := sha256.Sum256([]byte(hashing))
|
||||
var sha []byte
|
||||
@ -49,7 +65,6 @@ func (p *Passage) GetPassword(door string) string {
|
||||
sha = append(sha, shaArr[i])
|
||||
}
|
||||
for i := 0; i < p.length; i++ {
|
||||
//for i := range sha {
|
||||
ret += string(validChars[int(sha[i])%len(validChars)])
|
||||
}
|
||||
return ret
|
||||
|
Loading…
Reference in New Issue
Block a user