allowances/db.go

33 lines
642 B
Go
Raw Normal View History

2013-02-21 00:19:21 -08:00
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)
}
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(*check_pw))
if err == nil {
result = true
return
}
}
return
}