diff options
author | Michael Hunteman <huntemanmt@gmail.com> | 2025-01-25 21:16:41 -0600 |
---|---|---|
committer | Michael Hunteman <huntemanmt@gmail.com> | 2025-01-25 21:16:41 -0600 |
commit | 5d38bcdee9f047ad4cc6e533a14bfede7f41ab2f (patch) | |
tree | c4823c96834fac124de86aee38b953311f9920c2 | |
parent | 417ce259cacea581ab84336f46d881558dd4b4fc (diff) |
Hash password
-rw-r--r-- | server/admin/store.go | 7 | ||||
-rw-r--r-- | server/cmd/main.go | 5 | ||||
-rw-r--r-- | server/go.mod | 12 | ||||
-rw-r--r-- | server/go.sum | 12 |
4 files changed, 26 insertions, 10 deletions
diff --git a/server/admin/store.go b/server/admin/store.go index 65b905a..3322b35 100644 --- a/server/admin/store.go +++ b/server/admin/store.go @@ -6,6 +6,7 @@ import ( "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgxpool" + "golang.org/x/crypto/bcrypt" ) type Store struct { @@ -41,9 +42,13 @@ func createAdmin(requestAdmin Admin, adminRows pgx.Rows) (Admin, bool) { return Admin{}, false } if databaseAdmin.Username == requestAdmin.Username && - databaseAdmin.Password == requestAdmin.Password { + verifyPassword(databaseAdmin.Password, requestAdmin.Password) { return databaseAdmin, true } } return Admin{}, false } + +func verifyPassword(hashedPassword string, password string) bool { + return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password)) == nil +} diff --git a/server/cmd/main.go b/server/cmd/main.go index 75caf19..f9da6ce 100644 --- a/server/cmd/main.go +++ b/server/cmd/main.go @@ -8,11 +8,10 @@ import ( "os" "slices" - "github.com/jackc/pgx/v5/pgxpool" - "git.huntm.net/wedding/server/admin" "git.huntm.net/wedding/server/guest" "git.huntm.net/wedding/server/middleware" + "github.com/jackc/pgx/v5/pgxpool" ) var ( @@ -61,7 +60,7 @@ func writeMethods(responseWriter http.ResponseWriter, request *http.Request) { } func writeOrigins(responseWriter http.ResponseWriter, request *http.Request) { - allowedOrigins := []string{"http://localhost:5173", "http://192.168.1.25:5173"} + allowedOrigins := []string{"http://localhost:5173"} origin := request.Header.Get("Origin") if slices.Contains(allowedOrigins, origin) { responseWriter.Header().Add("Access-Control-Allow-Origin", origin) diff --git a/server/go.mod b/server/go.mod index 8ae7015..6e62f40 100644 --- a/server/go.mod +++ b/server/go.mod @@ -4,15 +4,15 @@ go 1.22.2 require ( github.com/golang-jwt/jwt/v5 v5.2.1 - github.com/jackc/pgx/v5 v5.6.0 + github.com/jackc/pgx/v5 v5.7.2 ) require ( github.com/jackc/pgpassfile v1.0.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect - github.com/jackc/puddle/v2 v2.2.1 // indirect + github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect + github.com/jackc/puddle/v2 v2.2.2 // indirect github.com/stretchr/testify v1.8.4 // indirect - golang.org/x/crypto v0.23.0 // indirect - golang.org/x/sync v0.7.0 // indirect - golang.org/x/text v0.15.0 // indirect + golang.org/x/crypto v0.32.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/text v0.21.0 // indirect ) diff --git a/server/go.sum b/server/go.sum index 590fe16..3465d95 100644 --- a/server/go.sum +++ b/server/go.sum @@ -7,10 +7,16 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= +github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY= github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw= +github.com/jackc/pgx/v5 v5.7.2 h1:mLoDLV6sonKlvjIEsV56SkWNCnuNv531l94GaIzO+XI= +github.com/jackc/pgx/v5 v5.7.2/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ= github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= +github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= @@ -20,10 +26,16 @@ github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcU github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI= golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8= +golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= +golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= |