r/javahelp • u/Roxose • Feb 20 '21
How to remember user's detail to avoid asking him to sign in everytime in JavaFx Desktop Application
I am trying to build an application that requires users to log in. When they register I store their information in the MySQL database. (For now, I am just using localhost) I don't want users to write their login details every time they open up the application. How can I avoid this? I am totally clueless. I will be very thankful if someone helps.
6
u/dionthorn this.isAPro=false; this.helping=true; Feb 20 '21
Here is the Java Security Overview
The specific packages you'll be most interested in for authentication and storage of information are:
"This package also supports the generation and storage of cryptographic public key pairs, as well as a number of exportable cryptographic operations including those for message digest and signature generation"
"Provides classes and interfaces for parsing and managing certificates, certificate revocation lists (CRLs), and certification paths."
"Provides classes for the secure socket package. Using the secure socket classes, you can communicate using SSL or a related security protocol to reliably detect any errors introduced into the network byte stream and to optionally encrypt the data and/or authenticate the communicating peers."
3
5
u/mayur217 Feb 20 '21
One solution would be using something similar to browser cookies. Once the user logs in, you can store that info in the local storage using some kind of encryption or base64 encoding(this is much easier to implement, but also not so secure). Along with credentials, you add a timestamp to the file and set an expiration duration. Everytime the user fired up the application, the file is read and the before credential verification, the timestamp is validated. If it isn't expired, simply auto login the user, if it is, then delete the local file and ask the user to login.
1
u/Roxose Feb 20 '21
Thank you for your answer. I wonder that what happens if someone steals the file I wrote the info and open my application in his computer. Wouldn't it sign in automatically to the original user's account? How can I prevent this?
4
u/mayur217 Feb 20 '21
Yes, for this exact problem I mentioned that you could use some kind of encryption to store info locally.
1
u/Roxose Feb 20 '21
Got it. Thank you very much. I know nothing about encryption but I will check it out.
1
u/jvjupiter Feb 21 '21
I’m currently developing a JavaFX application. My app is frontend only. Backend is separate, written in Spring Boot + Spring MVC + Spring Data JPA + Spring Security. I have my authentication service in backend. Login and refresh token endpoints respond with access token and refresh token. Using Retrofit, JavaFX calls these services. Tokens are being stored in Preferences. If a user just exits the app without logging out, the next time he/she opens the app, there is no login required anymore.
•
u/AutoModerator Feb 20 '21
Please ensure that:
Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
You include any and all error messages in full
You ask clear questions
You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.
Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar
If any of the above points is not met, your post can and will be removed without further warning.
Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.
Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.
Code blocks look like this:
You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.
If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.
To potential helpers
Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.