allowances/db.go

34 lines
721 B
Go

package main
import (
"code.google.com/p/go.crypto/bcrypt"
"github.com/kuroneko/gosqlite3"
"log"
"sync"
)
var dbMutex sync.Mutex
func check_password(attempt string) (result bool) {
db, err := sqlite3.Open(*db_file)
defer db.Close()
if err != nil {
log.Fatal(err)
}
// this feels ultra hokey ... I guess I could take it from 2N to N by |= ...
hashes := []string{}
cmd := "SELECT hash FROM passes;"
db.Execute(cmd, func(s *sqlite3.Statement, values ...interface{}) {
cur_hash := values[0].(string)
hashes = append(hashes, cur_hash)
})
for _, hash := range hashes {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(attempt))
if err == nil {
result = true
return
}
}
return
}