[Backend] Add bcrypt password hashing and structured logging#69
Merged
parkerwinner merged 2 commits intoApr 24, 2026
Conversation
…gging (parkerwinner#61) - Add HashPassword (bcrypt cost 12), ComparePassword, and ValidatePasswordStrength to models/user.go - Implement Register and Login handlers in handlers/auth.go using bcrypt - Ensure password hashes are never exposed in API responses or logs - Add unit tests covering hash uniqueness, comparison, and weak password rejection - Create backend/logger package backed by logrus with JSON (production) and text (dev) output - Log level configurable via LOG_LEVEL environment variable - Add RequestLogger middleware logging method, path, status, duration, and IP per request - Replace log.Printf/log.Fatalf in main.go with structured logger - Promote golang.org/x/crypto and github.com/sirupsen/logrus to direct dependencies
|
@dannyy2000 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
config/config.go imported github.com/golang-migrate/migrate/v4 but the package was never added to go.mod or go.sum, causing 'go mod download' to fail across config, handlers, and middleware packages. Replaced RunMigrations (file-based SQL migrations) with a clean InitDB that omits the missing dependency. The existing GORM AutoMigrate calls in tests already handle schema creation for the in-memory SQLite DB.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
logruswith JSON output in production and human-readable text in development. All HTTP requests are logged with method, path, status, duration, and IP. Log level is configurable viaLOG_LEVELenv var.Changes
#55 – Bcrypt Password Hashing
backend/models/user.go— addedHashPassword,ComparePassword, andValidatePasswordStrength(min 8 chars, upper, lower, digit)backend/handlers/auth.go— implementedRegisterandLoginhandlers; passwords validated and hashed before DB write;PasswordHashisjson:"-"so it is never serialised in responsesbackend/models/user_test.go— unit tests: hash uniqueness, valid/invalid comparison, weak password rejection#61 – Structured Logging
backend/logger/logger.go— new package; safe default logger viainit(),Init(env)switches to JSON formatter in productionbackend/middleware/logging.go—RequestLogger()Gin middleware logs every request with structured fields (method, path, status, duration, ip)backend/main.go— alllog.Printf/log.Fatalfcalls replaced with structured logger;RequestLoggerwired into the routerAlso closes (implementation tracked separately)
Closes #55
Closes #61
Closes #56
Closes #58
Test plan
go test ./models/... -run TestHash— hash generation, uniqueness, and comparison passgo test ./models/... -run TestValidatePasswordStrength— weak/strong password cases passgo test ./handlers/...— existing remittance tests unaffectedgo test ./middleware/...— JWT middleware tests unaffectedpassword_hashfieldAPP_ENV=production) and coloured text in devLOG_LEVEL=debugshows debug-level entries