Passage Library Works
This commit is contained in:
parent
3b416e625b
commit
f37377dd63
1
gopass-cmd/.gitignore
vendored
Normal file
1
gopass-cmd/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
gopass-cmd
|
18
gopass-cmd/main.go
Normal file
18
gopass-cmd/main.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
passage "gogs.bullercodeworks.com/brian/passage-go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) < 3 {
|
||||
fmt.Println("Usage: gopass <pin> <door>")
|
||||
os.Exit(1)
|
||||
}
|
||||
p := passage.CreatePassage(os.Args[1])
|
||||
fmt.Println("Checksum: " + p.GetChecksumAsString())
|
||||
fmt.Println("Password: " + p.GetPassword(os.Args[2]))
|
||||
}
|
69
passage.go
Normal file
69
passage.go
Normal file
@ -0,0 +1,69 @@
|
||||
package passage
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
const (
|
||||
UseLower = 1 << iota
|
||||
UseUpper
|
||||
UseNumber
|
||||
UseSymbol
|
||||
)
|
||||
|
||||
type Passage struct {
|
||||
valids int
|
||||
length int
|
||||
pin string
|
||||
}
|
||||
|
||||
func CreatePassage(pin string) *Passage {
|
||||
p := new(Passage)
|
||||
p.length = 20
|
||||
p.valids = UseLower | UseUpper | UseNumber | UseSymbol
|
||||
p.pin = pin
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Passage) SetPin(pin string) {
|
||||
p.pin = pin
|
||||
}
|
||||
|
||||
func (p *Passage) GetPassword(door string) string {
|
||||
ret := ""
|
||||
validChars := ""
|
||||
if p.valids&UseLower == UseLower {
|
||||
validChars += "abcdefghijklmnopqrstuvwxyz"
|
||||
}
|
||||
if p.valids&UseUpper == UseUpper {
|
||||
validChars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
}
|
||||
if p.valids&UseNumber == UseNumber {
|
||||
validChars += "1234567890"
|
||||
}
|
||||
hashing := p.pin + " - " + door
|
||||
shaArr := sha256.Sum256([]byte(hashing))
|
||||
var sha []byte
|
||||
for i := range shaArr {
|
||||
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
|
||||
}
|
||||
|
||||
func (p *Passage) GetChecksum() int {
|
||||
ret := 0
|
||||
sha := sha256.Sum256([]byte(p.pin))
|
||||
for i := range sha {
|
||||
ret += int(sha[i])
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func (p *Passage) GetChecksumAsString() string {
|
||||
return strconv.Itoa(p.GetChecksum())
|
||||
}
|
Loading…
Reference in New Issue
Block a user