Java storing user preferences - java

I'm making a program with a simple GUI, where the user have to do the login before starting use the program.
I want to store username and password and, if the user check the "Remember me" checkbox, i want that he doesn't need to enter data next time.
I tried doing with Java Preferences API, this way:
private Preferences prefs = Preferences.userRoot().node(this.getClass().getName());
prefs.put("codCliente", txtCodCliente.getText());
prefs.put("username", txtUsername.getText());
prefs.put("password", DigestUtils.md5Hex(String.valueOf(txtPassword.getPassword())));
But if i close and reopen the app, if i print the content of variables, it returns "Null key" NullPointerException.
I tried to save them in a .properties file, but I don't want to overwrite every time the whole file, and if I try to use apache commons configuration, with setProperty, I can't put the value on the variables.
Which is the best way to store this kind of data?
Thank you all.

Yes preferences is really easy and good way of doing this , problem is that:
he doesn't need to enter data next time
That means he WONT PUT ANYTHING INTO TEXT FIELDS.
But if i close and reopen the app, if i print the content of
variables, it returns "Null key" NullPointerException.
What did you expected? You put this NULL values into preferences again as he starts his app again.
Problem is in your design
application starts->
read preference of checkbox state->
{reread login credentials} else {nothing} ->
show login ui , user enters credentials ->{compare credentials to whose with preferences} DONT STORE ANYTHING , why woud you store what user is trying to login with every single time you start application?
You only store credentials at user creation ,use encryption and store your data, for both name , and password.
In your question there is not enough code to help you out directly with code sample , you have problem with design , where you reading this information in your code? Why dont you post this part here? You only show us that you store soemthing , well ok , thats useless to person thats trying to help you out.
I recommend you to SIT DOWN, stop writing code , and write yourslef flowchart of your application startup and login process all the way with when you read/write anything to preferences etc.

Related

How to make a save function for a java based android app?

I have an app that encrypts inputs and I want to put a save function that will let users access the "notes" at any time. I thought about adding each in output to an ArrayList, but I still don't know how to save it and display it for the user to select. If you need me to clarify anything I'd be happy to. Thanks.

capture user asked data from echo

I'm writing a code for Amazon Alexa. And in the developer.amazon.com, we configure the intents, utterances etc... Here I need to get the question asked by the user.
I'm sure that this works using the intents but I will need the utterances. For eg:
GetTheData get me the user data
GetTheData get me user details
Here I'm able to get the GetTheData printed using intent.getName(), But i want to know if there is a way to get the content after the intent name i.e. get me the user data. I want to know this for my research purpose.
Please let me know how can I get this.
Thanks
No, unfortunately there is no way to get this information with the ASK/echo.
Your only solutions at this time would be to split that into one intent per utterance, or switch to google home (its SDK can give you the raw user text).

How to run a com add-in (with log-in and password) with VBA (or maybe other solutions)

update post of screenshotsI've got an COM excel add-in (name; Syntess Atrium Office add-in) which has a login button. When pushed i need to give a path to it's location on the server and after that I need a password to log in.
I need to run this Excel file a couple of times each month late at night with a scheduled task, and every time I need to be logged-in for it to function. So to make sure i'm always logged-in I want to create either a VBA script or any other script to push the log-in button, write down the path, hit enter, and then use my password and hit enter again.
The application (VBA excel sheet) runs at night because it takes several hours to create because of it's huge amount of data it takes from our financial database on the server(using the com add-in).
I hope someone can help me out!
I know I can use programs like Acces or even Excel it self for a direct link with the database, but our directors won't allow this, so that's not an option unfortunately.
If you can view the reference in the object browser you can start to get an idea of the functions (if exposed) that you can use.
You can see from the image below that the class DOMDocument60 (XML Document Object Model) has a loadXML function that "loads the document from a string".
Normally you would not have to use the object viewer as this same information is generally provided by the company:
MSDN - MSXML3.0/6.0 - 'loadXML'
However, if there is no public API available you may be able to read through the object and get an understanding of what you can call.
---If you can't find a 'login' function your best bet is to ask the company to expose such a method (function).

I want my old data even I refresh the webpage

First Question:
Consider, I am filling any form then I refresh that page,what I want is what ever I fill in that page should not clear not only refresh page even if network problem occurred during filling the form.
Second Question:
If I login with any username and password then I fill in form and if network problem occurrs during filling the form then I go to another machine and login with same username password, I want whatever I entered In previous system should be show in this machine.
Sorry for my poor english, please tell any idea.
You should try and leverage client side storage. This will allow you to store the user data on the local browser. Here is an article on this http://www.html5rocks.com/en/tutorials/offline/storage/
I hope it helps
Fixing the following requires:
1 - Background worker on the client side that posts the data to the server .
Worker;
//or
window.setInterval();
2 - A banner or a status div showing the user that he is connected or disconnected.
var isOnline = window.navigator.onLine;
3 - Notify the user about reloading the page.
window.addEventListener("beforeunload", function (e) { alert('Your leaving...') });
Your first question has a pretty simple and straightforward solution: you'd want to save the data on the local machine, using something like cookies or localStorage.
For your second question, you'd need a much more complicated solution. Basically, you need to constantly persist the view data (input values, etc.) to the server for "safekeeping", since you assume the machine might crash at any given moment.
So your backend should support saving "temp form data", and whenever a user enters the relevant screen, you need to check for such temp form data on the backend, and populate the form accordingly. This will probably cause lots of edge cases and isn't trivial IMO.

Save input user in Edittex

Good morning, I need help,
I´m new using Java in Android development and need to save user input in a textbox without needing a button to trigger it.
Could someone give an example please?
You will need a TextWatcher, since you do not want to trigger a click event
Here! is a good example of TextWatcher control,
once you get families to TextWatcher, you can save your value either in a SharedPreference (Local tiny storage) or in a Databse, Refere This! for storing and retrieving values from SharedPreference

Categories