efrem-upt / ShelterMe

ShelterMe is a desktop app developed in Java. It's main scope is to unite people affected from all places of the world with the people that are there to help them

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Note: This application is a college project that presents our skills and work. It may or may not be supported in the future with updates.

ShelterMe is a desktop app developed in Java. It's main scope is to unite people affected from all places of the world with the people that are there to help them. Project made for the Foundations of Software Engineering lab by @SebiGabor and @dragosefrem, during our second year of Computer Engineering studies at Polytechnic University of Timișoara. Technologies used:

Prerequisites

To be able to install and run this project, please make sure you have installed Java 17 or higher. Otherwise, the setup will note work! To check your java version, please run java -version in the command line.

To install a newer version of Java, you can go to Oracle or OpenJDK.

It would be good if you also installed Maven to your system. To check if you have Maven installed run mvn -version.

If you need to install any of them, please refer to this Maven tutorial.

Make sure you install JavaFX SDK on your machine, using the instructions provided in the Official Documentation. Make sure to export the PATH_TO_FX environment variable, or to replace it in every command you will find in this documentation from now on, with the path/to/javafx-sdk-18/lib.

Setup & Run

To set up and run the project locally on your machine, please follow the next steps.

Clone the repository

Clone the repository using:

git clone https://github.com/ShelterMe-app/ShelterMe

Verify that the project Builds locally

Open a command line session and cd ShelterMe. If you have installed all the prerequisites, you should be able to run any of the following commands:

mvn clean install

If you prefer to run using the wrappers, you could also build the project using

./mvnw clean install (for Linux or MacOS)
or 
mvnw.cmd clean install (for Windows)

Open in IntelliJ IDEA

To open the project in IntelliJ idea, you have to import it as a Maven project. After you import it, in order to be able to run it, you need to set up your IDE according to the official documentation. Please read the section for Non-Modular Projects from IDE. If you managed to follow all the steps from the tutorial, you should also be able to start the application by pressing the run key to the left of the GUIStarter (or Main) class.

Run the project with Maven

The project has already been setup for Maven according to the above link. To start and run the project use one of the following commands:

  • mvn javafx:run or ./mvnw javafx:run (run the run goal of the javafx maven plugin)

To understand better how to set up a project using JavaFX and Maven, please check the official OpenJFX documentation.

You should see an application starting, that looks like this:

Pressing on the Sign up button will redirect to the following window:

And the main page after logging in looks like this:

Technical Details

Encrypting Passwords

Encrypting the passwords is done via the following 2 Java functions, found in UserService.java:

    private static String encodePassword(String salt, String password) {
        MessageDigest md = getMessageDigest();
        md.update(salt.getBytes(StandardCharsets.UTF_8));

        byte[] hashedPassword = md.digest(password.getBytes(StandardCharsets.UTF_8));

        // This is the way a password should be encoded when checking the credentials
        return new String(hashedPassword, StandardCharsets.UTF_8)
                .replace("\"", ""); //to be able to save in JSON format
    }

    private static MessageDigest getMessageDigest() {
        MessageDigest md;
        try {
            md = MessageDigest.getInstance("SHA-512");
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException("SHA-512 does not exist!");
        }
        return md;
    }

Nitrite Java

Nitrite Java was used in the UserService.java file, where we initialized a database, and a Repository of User objects:

    private static ObjectRepository<User> userRepository;

    public static void initDatabase() {
        Nitrite database = Nitrite.builder()
                .filePath(getPathToFile("registration-example.db").toFile())
                .openOrCreate("test", "test");

        userRepository = database.getRepository(User.class);
    }

This Repository was further used to add new users, by using the insert method:

    public static void addUser(String username, String password, String role) throws UsernameAlreadyExistsException {
        checkUserDoesNotAlreadyExist(username);
        userRepository.insert(new User(username, encodePassword(username, password), role));
    }

and to find all users, by using the find method:

    private static void checkUserDoesNotAlreadyExist(String username) throws UsernameAlreadyExistsException {
        for (User user : userRepository.find()) {
            if (Objects.equals(username, user.getUsername()))
                throw new UsernameAlreadyExistsException(username);
        }
    }

Resources

To understand and learn more about JavaFX, you can take a look at some of the following links:

To better understand how to use Nitrite Java, use the following links:

About

ShelterMe is a desktop app developed in Java. It's main scope is to unite people affected from all places of the world with the people that are there to help them

License:Apache License 2.0


Languages

Language:Java 97.3%Language:CSS 2.7%