Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java - How to store multiple username/password combos

  • 25-03-2012 01:38AM
    #1
    Registered Users, Registered Users 2, Paid Member Posts: 8,009 ✭✭✭
    Something about sandwiches


    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

  • Posts: 0 ✭✭✭ [Deleted User]


    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, Registered Users 2, Paid Member Posts: 8,009 ✭✭✭The_B_Man
    Something about sandwiches


    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, Registered Users 2, Paid Member Posts: 8,009 ✭✭✭The_B_Man
    Something about sandwiches


    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, Registered Users 2 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, Registered Users 2 Posts: 4,958 ✭✭✭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,338 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, Registered Users 2, Paid Member Posts: 8,009 ✭✭✭The_B_Man
    Something about sandwiches


    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,338 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, Registered Users 2, Paid Member Posts: 8,009 ✭✭✭The_B_Man
    Something about sandwiches


    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