jaygajera17 / E-commerce-project-springBoot

This project serves as an easy-to-understand setup for beginners , providing a base foundation in Spring Boot , MVC & hibernate.
https://jaygajera17.github.io/E-commerce-project-springBoot/
520 stars 512 forks source link

No validation for duplicate username during registration #45

Closed kliu57 closed 7 months ago

kliu57 commented 8 months ago

Steps to reproduce this issue:

  1. Start the server and go to the user registration page http://localhost:8080/register

  2. Enter valid data and a non-existing username and click Register. Check the database to make sure the new user appears as a new row in the customer table. screenshot1

  3. Go back to the registration page and enter the same details again. Check the database and the new duplicate user is created.

screenshot2

Reason this is a problem:

Customers should not be allowed to register with an existing username. customers table username column should have a unique constraint to not allow duplicate usernames.

Proposed fix:

  1. Change the basedata.sql script to have a UNIQUE constraint on the username column of the customers table.

In models/User, define a unique constraint on the username field with @Column(unique = true)

  1. Change the source code to check if a username is an existing username or not. If it is existing, display an error message on the page. If it is not existing, create the user and redirect the user to the login page.