{"id":21980236,"url":"https://github.com/parinaz11/library","last_synced_at":"2025-03-23T01:14:19.106Z","repository":{"id":253226863,"uuid":"842867074","full_name":"Parinaz11/Library","owner":"Parinaz11","description":"This project was developed to manage book reservations in a library as part of a project-oriented Java Spring Boot backend course, overseen by Dotin Company.","archived":false,"fork":false,"pushed_at":"2024-10-23T10:31:45.000Z","size":4351,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-28T04:25:50.172Z","etag":null,"topics":["backend","backend-api","java","java-rest-api","java-springboot","javaspringboot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Parinaz11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-15T09:11:21.000Z","updated_at":"2024-10-23T10:31:49.000Z","dependencies_parsed_at":"2025-01-28T04:25:30.324Z","dependency_job_id":"fe182d5f-6ad5-48e7-86d2-999edfbcc6d1","html_url":"https://github.com/Parinaz11/Library","commit_stats":null,"previous_names":["parinaz11/library"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Parinaz11%2FLibrary","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Parinaz11%2FLibrary/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Parinaz11%2FLibrary/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Parinaz11%2FLibrary/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Parinaz11","download_url":"https://codeload.github.com/Parinaz11/Library/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245040691,"owners_count":20551308,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["backend","backend-api","java","java-rest-api","java-springboot","javaspringboot"],"created_at":"2024-11-29T17:10:09.091Z","updated_at":"2025-03-23T01:14:19.061Z","avatar_url":"https://github.com/Parinaz11.png","language":"Java","readme":"# Book Library Application (run LibraryApplication.java)\n\nFor REST API endpoints and program documentation, run the program and open http://localhost:8080/swagger-ui/index.html\n\nCheckout the h2 database at http://localhost:8080/h2-console with JDBC URL set to \"jdbc:h2:file:./data/library_database\"\n\nCommands in postman:\n\nGET localhost:8080/users\n\nGET localhost:8080/books\n\nGET localhost:8080/reservations\n\nCheckout custom exceptions with command GET GET localhost:8080/users/20 (since we don't have any user with id set to 20)\n\nFor UI:\n\nPOST localhost:8080/books\n\nbody:\n{\n    \"title\": \"DotinProject\",\n    \"author\": \"Maryam\",\n    \"available\": true,\n    \"pages\": 635,\n    \"user\": null\n}\n\nPOST localhost8080/users/13/reserve-book\n\nparams -\u003e bookName = DotinProject\n\nThen, the reservations will be shown at google calendar\n\n![Screenshot (613)](https://github.com/user-attachments/assets/d690004f-5068-4214-ba96-be4bdee5a81a)\n\n### Google Calendar UI\ndownload and add JAR file:\nhttps://mvnrepository.com/artifact/com.google.apis/google-api-services-calendar/v3-rev20220715-1.32.1\n\nWhat this project has:\n\nInteractive Terminal, Arraylist Database, *H2 Database and JPA Repository*, MongoDB Database, Swagger, 3-tier Architecture, Dependency Injection, slf4j Log, *Log with AOP*, *Custom Exceptions*, Entity Manager, Security and Validation, Unit Test, UI Using Google Calendar API\n---\n\n# Library Application with terminal (httpClient.java)\n\nAfter logging in and authorization, users are presented with a menu based on their role (User, Admin, or Manager). Each role has access to specific options in their menu, allowing them to perform actions appropriate to their role. Once their tasks are completed, they can exit the program by selecting the exit option\n\n## User Authentication and Password Hashing\n\n### Password Hashing in the `User` Class\n\nIn this library system, user authentication is handled securely by hashing passwords with the SHA-256 algorithm before storing them. This ensures that raw (plain-text) passwords are never stored in the database, reducing the risk of password exposure.\n\n### How Password Hashing Works\n\n1. **Salt Generation**:\n    - Before hashing the password, a unique salt is generated for each user. The salt is a random sequence of bytes that adds an additional layer of security to the hashing process. This prevents attackers from using precomputed tables (like rainbow tables) to crack the hash.\n    - The salt is generated using the `SecureRandom` class, which produces a cryptographically strong random value. The generated salt is then encoded into a string format using Base64 for easy storage.\n\n2. **Password Hashing**:\n    - Once the salt is generated, the password is hashed using the SHA-256 algorithm. The salt is combined with the password, and the resulting value is passed through the hashing algorithm.\n    - The `MessageDigest` class is used to perform the hashing. The hashed password is then encoded into a Base64 string, which is stored alongside the salt.\n\n3. **Storing and Verifying Passwords**:\n    - During user registration, the system generates a salt and hashes the user's password. The hashed password and salt are stored in the `User` object (and by extension, in the database).\n    - When a user attempts to log in, the system hashes the provided password using the same salt stored for that user. It then compares the resulting hash with the stored hash to verify the password.\n\n### Login Process\n\nUpon login, the system prompts the user to enter their username and password. The system retrieves the stored salt and hashed password associated with the username, hashes the entered password with the same salt, and compares the two hashes:\n\n- If the hashes match, the login is successful, and the user is granted access to the system.\n- If the hashes do not match, the login fails, and the user is prompted to try again.\n\nThis method of password storage and verification ensures that even if the database is compromised, the attackers would not have access to the user's plain-text passwords.\n___\n\n## User Class Methods\n\nThe `User` class in the library system allows users to interact with the library's book reservation system. Below is a description of the key methods:\n\n### `showAvailableBooks()`\nThis method displays a list of all books that are currently available for reservation. It checks the availability status of each book in the library and prints out the book's ID, title, author, and number of pages.\n\n### `reservationRequest(Scanner in)`\nThis method allows the user to request a reservation for a book. It prompts the user to enter the book's name, checks if the book is available, and if so, attempts to reserve it. If the reservation is successful, a confirmation message is displayed; otherwise, it informs the user that the reservation request failed because the book is already reserved.\n\n### `pendingReserveBooks()`\nThis method displays a list of all books that the user has requested to reserve but are still pending approval. It filters the user's reservations to show only those with a \"pending\" status, listing the reservation ID, book ID, and title of each pending book.\n\n### `deleteReserveRequest(Scanner in)`\nThis method allows the user to delete a pending reservation request. The user is prompted to enter the name of the book for which they want to cancel the reservation. If a matching reservation is found, and it belongs to the user, the reservation is deleted. A confirmation message is displayed upon successful deletion.\n\n### `showReservedBooks()`\nThis method shows all books that the user has successfully reserved. It filters the user's reservations to show only those with an \"approved\" status, listing the reservation ID, book ID, and title of each reserved book.\n\n### `getBookNameFromUser(Scanner in)`\nThis is a helper method that prompts the user to enter a book name. The entered name is then returned for further processing by other methods.\n\n### `Additional Utility Method:`\n- `showFilteredBooks(String stat)`: This helper method filters and displays books based on the reservation status provided (`\"pending\"` or `\"approved\"`). It is used by both `pendingReserveBooks()` and `showReservedBooks()` to avoid code duplication.\n\n### Menu Navigation:\n- `showMenu(Scanner in)`: This method displays the main menu to the user, allowing them to choose from the available actions (e.g., viewing available books, making a reservation). After the user selects an option, the corresponding method is called. The user is then asked if they wish to continue using the system.\n\n___\n### Admin Class\n\nThe `Admin` class extends the `User` class, providing additional capabilities for managing the library system:\n\n- `addBook()`: Allows the admin to add new books to the library by entering the book's title and author.\n- `removeBook()`: Enables the admin to remove books from the library by specifying the book's ID.\n- `showMenu(Scanner in)`: Displays a menu for the admin to choose actions like viewing all books, adding a book, removing a book, or viewing all users.\n- `runFuncForCommand(int choice, Scanner in)`: Executes the command selected from the menu, such as adding or removing a book.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparinaz11%2Flibrary","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparinaz11%2Flibrary","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparinaz11%2Flibrary/lists"}