Skip to content

A Spring Boot application for user authentication, featuring user registration, login, and forgot password functionality with OTP verification via email. Ideal for developers seeking a ready-made solution or reference for implementing similar features. Uses Spring Data JPA and JavaMailSender.

Notifications You must be signed in to change notification settings

JadhavC07/spring-boot-forgot-password-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

User Authentication System

This project is a Spring Boot application that handles user authentication with features like user registration, login, password reset using OTP (One-Time Password) sent to the user's email, OTP verification, and password reset functionality.

Features

  • User Registration
  • User Login
  • Forgot Password
  • OTP Verification
  • Password Reset

Technologies Used

  • Spring Boot
  • Spring Data JPA
  • Java Mail Sender
  • MySQL Database (can be replaced with other databases like H2, PostgreSQL, etc.)
  • Lombok (for reducing boilerplate code)
  • Maven

Setup Instructions

  1. Clone the repository:
    git clone https://github.com/yourusername/user-authentication-system.git
    cd user-authentication-system
  1. Configure Database: The application uses H2 database by default. You can configure another database in application.properties.

  2. Update Email Configuration: Configure your email settings in application.properties:

spring.mail.host=smtp.your-email-provider.com spring.mail.port=587 spring.mail.username=[email protected] spring.mail.password=your-email-password spring.mail.properties.mail.smtp.auth=true spring.mail.properties.mail.smtp.starttls.enable=true

  1. Run the Application: mvn spring-boot:run

  2. The application will be running at http://localhost:8080. API Endpoints Registration URL: /api/users/register Method: POST Request Body:

{ "username": "user1", "password": "password123", "email": "[email protected]" }

Response: 201 Created

Login URL: /api/users/login Method: POST Request Body:

{ "username": "user1", "password": "password123" }

Response: 200 OK with user details Forgot Password

URL: /api/users/forgot-password Method: POST Request Body: { "email": "[email protected]" } Response: 200 OK

Verify OTP URL: /api/users/verify-otp Method: POST Request Params:

email: User's email

otp: OTP received in the email

Response: 200 OK

Reset Password URL: /api/users/reset-password Method: POST Request Body: { "email": "[email protected]", "newPassword": "newPassword123" } Response: 200 OK

Project Structure entity: Contains the Users entity class. repository: Contains the UserRepository interface for database operations. service: Contains service classes UserService and EmailService. controller: Contains the UserController class for handling API requests. payload: Contains DTO classes LoginRequest, ForgotPasswordRequest, and ResetPasswordRequest.

Contribution Feel free to fork this project and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.

About

A Spring Boot application for user authentication, featuring user registration, login, and forgot password functionality with OTP verification via email. Ideal for developers seeking a ready-made solution or reference for implementing similar features. Uses Spring Data JPA and JavaMailSender.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages