Works sorta
This commit is contained in:
23
wiegand.go
23
wiegand.go
@@ -1,7 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"golang.org/x/crypto/scrypt"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -36,7 +39,7 @@ func printCardId(card uint64) {
|
||||
fmt.Printf("\n")
|
||||
}
|
||||
|
||||
func (w *Wiegand) cardRunner() {
|
||||
func (w *Wiegand) cardRunner(validUids ValidUids) {
|
||||
for {
|
||||
// Wait for bit timeout
|
||||
fmt.Printf("Waiting for bit timeout\n")
|
||||
@@ -56,6 +59,24 @@ func (w *Wiegand) cardRunner() {
|
||||
|
||||
printCardId(card)
|
||||
|
||||
b := make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(b, card)
|
||||
hashed, err := scrypt.Key(b, []byte("hashsah"), 16384, 8, 1, 64)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
hashedHex := hex.EncodeToString(hashed)
|
||||
fmt.Println(hashedHex)
|
||||
|
||||
_, ok := validUids[hashedHex]
|
||||
if ok {
|
||||
fmt.Println("Opening door")
|
||||
w.OpenDoor()
|
||||
} else {
|
||||
fmt.Println("Unknown card")
|
||||
}
|
||||
|
||||
w.bitNr = 0
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user