A simple Node.js application with PostgreSQL for secure user registration and login, using bcrypt for password hashing and EJS for templating.
- Features
- Tech Stack
- Getting Started
- Database Setup
- Available Routes
- Screenshots
- Project Structure
- Security Notes
- License
- Author
- User registration with hashed passwords using bcrypt
- Login authentication with password comparison
- Secure PostgreSQL integration with parameterized queries
- Simple EJS frontend templates
- Clear error handling and user feedback
- smtp gmail service for verificatin,reset password e.tc
- Backend: Node.js, Express
- Database: PostgreSQL
- Templating Engine: EJS
- Middleware: body-parser, morgan
- Security: bcrypt
- Clone the repository:
git clone https://github.com/your-username/secure-auth-app.git
cd secure-auth-app
- Install dependencies:
npm install
-
Create
views/
folder and add these.ejs
files:index.ejs
(homepage)login.ejs
(login form)secrets.ejs
(protected page after login)
-
Start the development server:
node index.js
Server runs on http://localhost:3000
- Open PostgreSQL CLI or pgAdmin.
- Create a new database:
CREATE DATABASE Secure;
- Create the
users
table:
CREATE TABLE users (
id SERIAL PRIMARY KEY,
email VARCHAR(255) UNIQUE NOT NULL,
password TEXT NOT NULL
);
Method | Route | Description |
---|---|---|
GET | / |
Home page |
GET | /login |
Login form |
POST | /register |
Register new user |
POST | /user-login |
Authenticate existing user |
All screenshots are stored in the
/screenshots/
folder.
secure-auth-app/
├── views/
│ ├── index.ejs
│ ├── login.ejs
│ └── secrets.ejs
├── screenshots/
│ ├── homepage.png
│ ├── login.png
│ ├── register.png
│ └── secrets.png
├── index.js
├── package.json
└── README.md
- Passwords are hashed using bcrypt with 12 salt rounds.
- SQL queries use parameterized values to prevent SQL injection.
- In production, database credentials should not be hardcoded. Use environment variables and
dotenv
.
DB_USER=postgres
DB_HOST=localhost
DB_NAME=Secure
DB_PASS=your_password
DB_PORT=5432
Then in index.js
, use:
import dotenv from "dotenv";
dotenv.config();
const db = new pg.Client({
user: process.env.DB_USER,
host: process.env.DB_HOST,
database: process.env.DB_NAME,
password: process.env.DB_PASS,
port: process.env.DB_PORT
});
This project is licensed under the MIT License.
Feel free to use, modify, and share.
Erick Olando
🎓 Meteorologist & 💻 Software Developer
📫 Email: erickolando98@gmail.com
🔗 GitHub | LinkedIn