Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java - How to store multiple username/password combos

Options
  • 25-03-2012 1:38am
    #1
    Registered Users Posts: 7,865 ✭✭✭


    I've to iterate through a variable number of logon credentials, so need to store them somehow. They'll be stored in a properties file (comma seperated, one line per credentials), read in, and stored for use.

    I'm just curious about peoples opinions on how I should do this. I was thinking a 1 dimensional array, but then I'll need to still separate them by comma into another array, as I use them separately later. While I could do this, I'm not sure if its the most efficient, or suitable.

    I was thinking some sort of key value pair, but I wont know the "key" to access the "value".

    Any suggestions?

    Thanks.


Comments

  • Registered Users Posts: 5,246 ✭✭✭conor.hogan.2


    A database?

    It does not have to be a "full blown" DB, something like SQLite would do if you are concerned of size etc

    This may even be overkill, it depends on size/time and other considerations.

    I am confused in what your question is. Can you elaborate as to why you will not know the key? Get it from user input?

    A hastable seems like a good choice, wait for other suggestions though.


  • Registered Users Posts: 7,865 ✭✭✭The_B_Man


    nah, a DB is overkill. It doesnt need any persistance. The file itself is the "database". I just need to read them in.

    Like I said, I was gonna go for the array, but was just wondering if there was a better way. Maybe an arraylist or something.


  • Registered Users Posts: 7,865 ✭✭✭The_B_Man


    OK, maybe I should elaborate.

    It'll be for a tester. They'll be testing stuff under different credentials. They'll have the CSV credentials stored somewhere. I don't know what they'll be, or how many there'll be.

    I'm just writing code to automate the authentication and return a session ID. They provide credentials, I provide the session.

    So with the session ID, they'll be able to login and do some stuff. When they're finished with each user, they'll want to try it under another login so will call something like "getNextUser()" and i'll do my stuff and return the next session ID.

    Now, what I'm trying to do is make it easy for me to write this "getNextUser()" method. I was thinking if I used an array I could just increment an integer and access the next set of credentials to use to login and get the session ID. The only thing with that is it seems a bit basic to be efficient, and I'm just looking for input how to make it better.


  • Registered Users Posts: 1,645 ✭✭✭k.p.h


    “Sometimes the questions are complicated and the answers are simple.”
    -Dr.Seuss

    I think an array will do the job.


  • Registered Users Posts: 4,845 ✭✭✭shootermacg


    If you are adamant that you do not want to use a relational database, then to persist values you only have one alternative and that is to write to file.
    if it is indeed files you want to write to you could use csv or object serialisation.
    What language are you using?


  • Advertisement
  • Moderators, Technology & Internet Moderators Posts: 1,335 Mod ✭✭✭✭croo


    Since the information is coming from a properties file, the java.util.Properties object seems like the natural option.

    http://docs.oracle.com/javase/6/docs/api/java/util/Properties.html


  • Registered Users Posts: 7,865 ✭✭✭The_B_Man


    Cheers for that croo. I didnt even know such a class existed! :D

    Do you know if that can read in from a CSV File?


  • Moderators, Technology & Internet Moderators Posts: 1,335 Mod ✭✭✭✭croo


    The_B_Man wrote: »
    Cheers for that croo. I didnt even know such a class existed! :D

    Do you know if that can read in from a CSV File?
    I've worked on a few projects where this class is used to create & share a common context to link the system together.

    The other common use is for the write/load the .properties files to define the configuration of an application. I've not seen it used to load a CSV file. If I have different users & environments to test, I create different .properties files for each and pass those property files as a parameter to the application at startup. It doesn't sound like that is what you need!?

    I guess, you might write some code to parse the csv file an create an array of Properties - it's basically just a mechanism to manage key/value lists.


  • Registered Users Posts: 7,865 ✭✭✭The_B_Man


    Well I've to write something for a tester. they'll presumably want to have a properties file with the usernames and passwords. I've got it working in the form user=pass but no luck on the CSV.
    Suppose I could write another method that handles CSV format. But for now, the user=pass works fine.


Advertisement