0

I am writing an android application that requires the user to create an account and then login in order to access data pulled from an external source (and locally on device). I am trying to write the register code and am stuck on what the best approach to use.

At the moment, I am thinking I should be creating shared preferences to store the username and password on the device and then writing the data to an external source via a db call.

So what i want the workflow to look like is this:

  1. User opens application on device
  2. User is presented with splashscreen with "Login" and "Register" buttons.
  3. User selects "Register" and enters basic info (name,email,preferred username,password)
  4. User clicks Register button
  5. OnClick creates the shared preference and connects to the db to write the user credentials.
  6. User is re-directed to the main activity
  7. User closes app
  8. User opens app and is automatically logged into application.

At the moment I have 2 classes, a register.java that contains the UI and an AccountPreferences.java that contains the logic. Is this the best approach?

Also, is creating shared preferences and then creating a separate db call here the best solution? I tried looking into AccountManager but found this ridiculously complicated. I want to make sure I code it right the first time without having to re-write if there is a better way of doing this.

Thanks in advance,

Scott.

user3234459
  • 61
  • 1
  • 8

1 Answers1

0

Your workflow is not that bad, but I would make the following changes:

  1. After Register, I would redirect to Login activity instead to the main activity
  2. In Login activity when Login button is clicked, check if Username and Password match. If matched save them to your SharedPreferences and move to main activity. If not matched, show a warning and clear Username and Password fields.
  3. SharedPreferences whilst being the best option for storing preferences, it is always better to weight out security issues. Read this answer for more details.

Note: This kind of questions are usually frowned upon in SO, because they are opinions based.

Community
  • 1
  • 1
Lazy Ninja
  • 22,342
  • 9
  • 83
  • 103