got logging in to work
This commit is contained in:
parent
bc53e1a1ff
commit
669c63d560
3
db.go
3
db.go
@ -15,6 +15,7 @@ func check_password(attempt string) (result bool) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
// this feels ultra hokey ... I guess I could take it from 2N to N by |= ...
|
||||||
hashes := []string{}
|
hashes := []string{}
|
||||||
cmd := "SELECT hash FROM passes;"
|
cmd := "SELECT hash FROM passes;"
|
||||||
db.Execute(cmd, func(s *sqlite3.Statement, values ...interface{}) {
|
db.Execute(cmd, func(s *sqlite3.Statement, values ...interface{}) {
|
||||||
@ -22,7 +23,7 @@ func check_password(attempt string) (result bool) {
|
|||||||
hashes = append(hashes, cur_hash)
|
hashes = append(hashes, cur_hash)
|
||||||
})
|
})
|
||||||
for _, hash := range hashes {
|
for _, hash := range hashes {
|
||||||
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(*check_pw))
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(attempt))
|
||||||
if err == nil {
|
if err == nil {
|
||||||
result = true
|
result = true
|
||||||
return
|
return
|
||||||
|
11
handlers.go
11
handlers.go
@ -1,7 +1,6 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,8 +15,12 @@ func homeHandler(w http.ResponseWriter, req *http.Request) {
|
|||||||
|
|
||||||
func loginHandler(w http.ResponseWriter, req *http.Request) {
|
func loginHandler(w http.ResponseWriter, req *http.Request) {
|
||||||
pwAttempt := req.FormValue("passwd")
|
pwAttempt := req.FormValue("passwd")
|
||||||
// if pw matches, set session.Values["logged in"], then redirect to "/"
|
if check_password(pwAttempt) {
|
||||||
// else come back here..
|
session, _ := store.Get(req, "creds")
|
||||||
log.Printf("%v\n", pwAttempt)
|
session.Values["logged in"] = true
|
||||||
|
session.Save(req, w)
|
||||||
|
http.Redirect(w, req, "/", http.StatusSeeOther)
|
||||||
|
return
|
||||||
|
}
|
||||||
T("login.html").Execute(w, map[string]interface{}{})
|
T("login.html").Execute(w, map[string]interface{}{})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user