Skip to content

Commit 84992b7

Browse files
committed
Add password hashing to loginHandler
Will create user management page for admins soon as well. This will be fine for the time being though -> https://www.dailycred.com/article/bcrypt-calculator for generating hashes.
1 parent ef80d2b commit 84992b7

File tree

4 files changed

+14
-4
lines changed

4 files changed

+14
-4
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@ feed\.rss
2121

2222
assets/static/custom\.css
2323

24-
config\.json
24+
config\.json
25+
vendor/

Godeps/Godeps.json

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

assets/config/users.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"admin": "password1",
3-
"gabriel": "password"
2+
"admin": "$2a$04$ZAf88Bao4Q768vKfCaKBlOqtPumwKwFhrcpBCdfMWWFX69wyhgTqi",
3+
"gabriel": "$2a$04$KrhZ1q6FpOGqs0FVKMYhQ.BTYeVXztnjrM9RbK.0buI1OHfmyNEAy"
44
}

router/router.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"net/http"
99
"strings"
10+
"golang.org/x/crypto/bcrypt"
1011

1112
"github.com/gorilla/mux"
1213
"github.com/gmemstr/pogo/admin"
@@ -146,7 +147,7 @@ func loginHandler() common.Handler {
146147

147148
// Iterate through map until we find matching username
148149
for k, v := range u {
149-
if k == username && v == password {
150+
if k == username && bcrypt.CompareHashAndPassword([]byte(v), []byte(password)) == nil {
150151
// Create a cookie here because the credentials are correct
151152
c, err := auth.CreateSession(&common.User{
152153
Username: k,

0 commit comments

Comments
 (0)