This project is a web application built with Node.js that implements user authentication features including registration, login, password reset, and logout functionalities. The application uses Express.js for the backend server and MongoDB as the database to store user information securely.
- User Registration: Allows new users to create an account.
- User Login: Existing users can log in with their credentials.
- Password Reset: Users can reset their password if they forget it.
- Password Change: Users can change their password.
- Logout: Users can log out of their account securely.
- Node.js: JavaScript runtime for building server-side applications.
- Express.js: Web framework for Node.js.
- MongoDB: NoSQL database for storing user information.
- Mongoose: ODM for MongoDB to interact with the database.
- bcryptjs: Library to hash and compare passwords.
- EJS: Embedded JavaScript templates for rendering HTML pages.
-
Clone the repository:
git clone https://github.com/minnukota381/login-authentication-node.git cd login-authentication-node
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory and add the following variables:MONGODB_URI=<your-mongodb-connection-string> SESSION_SECRET=<your-session-secret>
-
Start the server:
npm start
The server will start on port 3000 by default. You can access it at
http://localhost:3000
.
-
Register a new user:
- Navigate to
http://localhost:3000/register
. - Fill in the registration form and submit.
- Navigate to
-
Login:
- Navigate to
http://localhost:3000/
. - Enter your username/email and password to log in.
- Navigate to
-
Forgot Password:
- Navigate to
http://localhost:3000/forgot-password
. - Enter your username and email to receive a password reset link.
- Navigate to
-
Reset Password:
- Navigate to the link received in your email.
- Enter your new password to reset.
login-authentication-node/
├── controllers/
│ └── authController.js
├── models/
│ └── User.js
├── routes/
│ └── authRoutes.js
├── views/
│ ├── login.ejs
│ ├── register.ejs
│ ├── forgot-password.ejs
│ └── reset-password.ejs
├── public/
│ ├── images/
│ │ ├── forget.svg
│ │ └── login.svg
│ │ └── register.svg
│ └── css/
│ └── login.css
│ └── register.css
│ └── reset-password.css
├── .env
├── .gitignore
├── app.js
├── package-lock.json
├── package.json
└── README.md
- GET /: Render the login page.
- POST /login: Handle user login.
- GET /register: Render the registration page.
- POST /register: Handle user registration.
- POST /logout: Handle user logout.
- GET /forgot-password: Render the forgot password page.
- POST /forgot-password: Handle forgot password form submission.
- GET /reset-password: Render the reset password page.
- POST /reset-password: Handle reset password form submission.
Contributions are welcome! Please follow these steps to contribute:
- Fork the repository.
- Create a new branch (
git checkout -b feature/your-feature
). - Make your changes.
- Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/your-feature
). - Create a new Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.