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)
|
|
|
|
}
|
2013-02-21 00:36:32 -08:00
|
|
|
// this feels ultra hokey ... I guess I could take it from 2N to N by |= ...
|
2013-02-21 00:19:21 -08:00
|
|
|
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 {
|
2013-02-21 00:36:32 -08:00
|
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(attempt))
|
2013-02-21 00:19:21 -08:00
|
|
|
if err == nil {
|
|
|
|
result = true
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|