save username and password on sign up and log him/her in if entered correct id and password on next logins

StackOverflow https://stackoverflow.com//questions/12668900

Question

as i m new to android application development .. i m making a passwords manager type of application ... so on the first page i have asked for username and password and a button for signup. if a person is running application for first time then he/she has to sign up and provide user id,password,security question for the case if he/she forgets his/her password. now i want to save the user id and password which user provide during signup in the application and next time when he/she again login and enters the user id and password then application should verify it from the saved user id and password and direct it to next page if he/she entered correct user id and password else a message should toast that "incorrect username or password ".

for this what coding in eclipse should i do..?

i had already made xml files i.e layouts..

thanks

Was it helpful?

Solution

You should save it in a file, i recommend using SharedPreferences and then read it from there each time they start the application, and see if the matches are correct or not.

To save it:

SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
editor.putString("username", "some user value");
editor.putString("password", "some password value");
editor.commit();

To get it:

SharedPreferences sp = context.getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
String username = sp.getString("username", null);
String password = sp.getString("password", null);
if(username != null && password != null){
    // login automatically with username and password    
}
else{
    // login for the first time
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top