git clone https://github.com/BlackFoxT/BasicLoginApp
This is a basic login application built with Spring Boot, Thymeleaf, and Spring Security. It allows users to sign up, log in using an email instead of a username, and restricts access to authentication pages for logged-in users.
- User authentication with Spring Security
- Uses email instead of username for login
- Sign-up functionality to create new accounts
- Restricts access to
/auth/loginand/auth/signupfor authenticated users - Displays user information on the main page after login
- Simple Thymeleaf templates for frontend rendering
- MySQL database integration for persistent user storage
- Encrypted password storage to ensure secure handling of user credentials
- Spring Boot
- Spring Security
- Thymeleaf
- Java 23+
- Maven
- MySQL
Ensure you have the following installed:
- Java 23+
- Maven
- MySQL (Make sure it's running)
git clone https://github.com/BlackFoxT/BasicLoginApp
cd BasicLoginAppFirst, create the database schema in MySQL:
CREATE SCHEMA your_database;
Edit src/main/resources/application.properties and set up your MySQL database details:
spring.datasource.url=jdbc:mysql://localhost:3306/your_database
spring.datasource.username=your_username
spring.datasource.password=your_passwordmvn spring-boot:runThe application will start at http://localhost:8080
| Endpoint | Description |
|---|---|
/ |
Main page displaying user info after login |
/auth/login |
Login page (only accessible to non-authenticated users) |
/auth/signup |
Signup page (only accessible to non-authenticated users) |
/auth/logout |
Logout endpoint |
- Email-based login: The application uses
emailinstead of the defaultusernameparameter. - Restricted pages: Logged-in users cannot access
/auth/loginand/auth/signup. - Session-based authentication with Spring Security.
In this securityFilterChain configuration, access permissions to pages are defined. The /auth/login and /auth/signup pages are accessible only to unauthenticated (anonymous) users. To enable login using an email instead of a username, the usernameParameter("email") has been set, so users can log in with their email address. The logout process is handled via the /auth/logout URL. After the user logs out, the system invalidates the session, deletes the JSESSIONID cookie, and redirects the user to the / page. This ensures users can safely log out.
This is example structure for the database.





