I am writing a java program, where the user has to login with their username and password. I want to enable the user to stay logged in, so that the login procedure does not need to be done for every start of the program.
My current implementation for this is to use java.util.pref.Preferences and store the username of the last logged in person and store whether this person should be automatically logged in. This works, but can easily be manipulated, as you could manually modify the Preferences values (by changing the values in HKEY_CURRENT_USER). One could then save some username in the Preferences and save that this user should be auto-logged in, and therefore the password could by bypassed. So this does not seem like a proper secure implementation.
In what way can that be implemented securely, so that the password cannot be bypassed by manipulating the stored data (easily)?