got storage of hashed passwords working
This commit is contained in:
parent
5f35227f21
commit
562b0311c1
@ -34,5 +34,9 @@ Dependencies
|
|||||||
- place in ./static/bootstrap
|
- place in ./static/bootstrap
|
||||||
|
|
||||||
|
|
||||||
|
Bootstrap DB
|
||||||
|
============
|
||||||
|
|
||||||
|
$ sqlite3 db.sqlite < init_db.sql
|
||||||
|
|
||||||
.. _bootstrap: http://twitter.github.com/bootstrap/assets/bootstrap.zip
|
.. _bootstrap: http://twitter.github.com/bootstrap/assets/bootstrap.zip
|
||||||
|
1
init_db.sql
Normal file
1
init_db.sql
Normal file
@ -0,0 +1 @@
|
|||||||
|
CREATE TABLE passes (id INTEGER PRIMARY KEY AUTOINCREMENT, hash STRING);
|
35
main.go
35
main.go
@ -1,19 +1,44 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"code.google.com/p/go.crypto/bcrypt"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
|
"github.com/kuroneko/gosqlite3"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
var addr = flag.String("addr", ":8000", "http service address")
|
var addr = flag.String("addr", ":8000", "address I'll listen on.")
|
||||||
var static_files = flag.String("static", "./static", "location of static files")
|
var static_files = flag.String("static", "./static", "location of static files")
|
||||||
|
var db_file = flag.String("db", "./db.sqlite", "the database")
|
||||||
|
var add_pw = flag.String("passwd", "", "add this pass to the db")
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
http.Handle("/s/", http.StripPrefix("/s/",
|
|
||||||
http.FileServer(http.Dir(*static_files))))
|
if *add_pw != "" {
|
||||||
if err := http.ListenAndServe(*addr, nil); err != nil {
|
hpass, err := bcrypt.GenerateFromPassword([]byte(*add_pw), bcrypt.DefaultCost)
|
||||||
log.Fatal("ListenAndServe:", err)
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
db, err := sqlite3.Open(*db_file)
|
||||||
|
defer db.Close()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
cmd := fmt.Sprintf("INSERT INTO passes ('id', 'hash') VALUES (null, '%v')",
|
||||||
|
string(hpass))
|
||||||
|
_, err = db.Execute(cmd)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
fmt.Printf("%v\n", *add_pw)
|
||||||
|
http.Handle("/s/", http.StripPrefix("/s/",
|
||||||
|
http.FileServer(http.Dir(*static_files))))
|
||||||
|
if err := http.ListenAndServe(*addr, nil); err != nil {
|
||||||
|
log.Fatal("ListenAndServe:", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user