| | |
Creating Login
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
•
•
Do I store the usernames in an array lisst and pictures inb and array list and then somehow match them together to allow the user a succesful login>?
The ID can be an int or string or...
Storage of the list of Username vs ID most probably has to be done persistantly. I would recommend not to use DB if this is the only reason you want to use it. Rather go for a simple flat/txt file would be easier.
I don't know why you feel storing it in a flatfile is better. That requires that you load the entire list while running, or that you write your own search routines to search for the user/id combination. With a DB you simply set of a query with the username as the search string and return the "id". No fuss, no muss. No loading the entire list into main memory, and no self-rigged search routines. And storing new user/id combos is just as easy as finding one. A single statement, and you're done. And this includes the possibility of a new user attempting to use the same name as a current user, when the username is the primary key, as the insert will fail with a primary key validation. With that, you no longer even have to check yourself whether a new username exists or not. Simply try to add it.
Last edited by masijade; Mar 26th, 2007 at 7:49 am. Reason: typo
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
•
•
That requires that you load the entire list while running, or that you write your own search routines to search for the user/id combination.

•
•
•
•
With a DB you simply set of a query with the username as the search string and return the "id".
1. Installation of DB?
2. Creation of DB table?
3. Code to create the DB connection?
4. Readup how to do step 1, 2 and 3 or ask someone???
I sure agree that once you're done with all this you'll "simply set of a query with the username as the search string and return the id".
•
•
•
•
No fuss, no muss. No loading the entire list into main memory, and no self-rigged search routines. And storing new user/id combos is just as easy as finding one. A single statement, and you're done.
Abt the "single stmt and you're done part" as I said earlier, it's not really true.
•
•
•
•
And this includes the possibility of a new user attempting to use the same name as a current user, when the username is the primary key, as the insert will fail with a primary key validation. With that, you no longer even have to check yourself whether a new username exists or not. Simply try to add it.
C++ Syntax (Toggle Plain Text)
#define MAX_LINE_LEN 100 int main() { FILE * pFile = fopen ("user_info.txt", "w+"); if( ! pFile ) { cout << "Could not open file" << endl ; return 1 ; } for( int i = 0; i < 10; i++ ) { char dummy[50] ; itoa(i, dummy, 10) ; fprintf (pFile, "%s %d\n", dummy, i); } rewind (pFile); map< string, int > usrInfMap ; char str [80]; int j; while( EOF != fscanf (pFile, "%s %d", str, &j) ) { usrInfMap[str] = j ; }; fclose (pFile); map< string, int >::iterator it = usrInfMap.begin(); for( ; it != usrInfMap.end(); it++ ) cout << it->first.c_str() << " = " << it->second << endl ; return 0; }
Now finally remember that I said earlier:
I would recommend not to use DB if this is the only reason you want to use it (=>DB).
•
•
•
•
True but I feel that would be easier !
As someone quoted earlier you've deceptively missed a few other things:
1. Installation of DB?
2. Creation of DB table?
3. Code to create the DB connection?
4. Readup how to do step 1, 2 and 3 or ask someone???
I sure agree that once you're done with all this you'll "simply set of a query with the username as the search string and return the id".
Here is the fuss/muss we'll have to do if we use flat file (see the code at end). Self-regged search routines? std::map gives it. map::find().
Abt the "single stmt and you're done part" as I said earlier, it's not really true.
See the return type of std::map::insert(). It does this for you. Again you don't write no code.
C++ Syntax (Toggle Plain Text)
#define MAX_LINE_LEN 100 int main() { FILE * pFile = fopen ("user_info.txt", "w+"); if( ! pFile ) { cout << "Could not open file" << endl ; return 1 ; } for( int i = 0; i < 10; i++ ) { char dummy[50] ; itoa(i, dummy, 10) ; fprintf (pFile, "%s %d\n", dummy, i); } rewind (pFile); map< string, int > usrInfMap ; char str [80]; int j; while( EOF != fscanf (pFile, "%s %d", str, &j) ) { usrInfMap[str] = j ; }; fclose (pFile); map< string, int >::iterator it = usrInfMap.begin(); for( ; it != usrInfMap.end(); it++ ) cout << it->first.c_str() << " = " << it->second << endl ; return 0; }
Now finally remember that I said earlier:
I would recommend not to use DB if this is the only reason you want to use it (=>DB).
Everything else you wrote is c++ not Java. Go crawl back under the rock you came from.
And, flat file system will never give you the type of security you want for a password system unless you encrypt them as well. Then you also have to self-rigg that encryption system, and even though the "password" here is simply a picture "id" it should still be encrypted. Nearly all mainstream dbs provide an easy way to encrypt entries, so even that is "done for you".
So remember, I say again, why do you think a flat file system is better?
Last edited by masijade; Mar 26th, 2007 at 1:18 pm.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
Wow is that coencidence that you both have avatars created by matt groening.
Ok, thnx for the replies aye. To be honest this doesnt even need security, all it really needs is different files stored for different userz.
I don't want to create a database so I like the flat txt file idea:-| .
Ill read through your comments and see if I can code this.
Ok, thnx for the replies aye. To be honest this doesnt even need security, all it really needs is different files stored for different userz.
I don't want to create a database so I like the flat txt file idea:-| .
Ill read through your comments and see if I can code this.
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
This is what I have so far. Btw im using J builder.
I've created the GUI and now I need to store the data when you Create Account.
So far all I managed was to make the comboBox contain the username.
I've created the GUI and now I need to store the data when you Create Account.
java Syntax (Toggle Plain Text)
//createAccountBtn pressed createAccountBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { userName = userNameInput.getText(); userBox.addItem(userName); } });
So far all I managed was to make the comboBox contain the username.
![]() |
Similar Threads
- How to create one login page in ASP.NET using C# (C#)
- Login Page Database connection to MSAccess (VB.NET)
- Creating login screens in VB6 (Visual Basic 4 / 5 / 6)
- Creating Login Page (ASP.NET)
- Creating a Login Page (ASP)
- Creating a login page (ASP)
- Simple ASP.Net Login Page (Using VB.Net) (ASP.NET)
Other Threads in the Java Forum
- Previous Thread: help me please...............
- Next Thread: creat a GUI solution
Views: 5438 | Replies: 22
| Thread Tools | Search this Thread |
Tag cloud for Java
android api apple applet application apps arguments array arrays automation awt binary bluetooth businessintelligence busy_handler(null) card chat class classes client code collision component constructor database draw eclipse error event eventlistener exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me jar java javafx javamicroeditionuseofmotionsensor javaprojects jmf jni jpanel jtree julia link linux list loop machine map method methods mobile netbeans newbie nls number object oracle parsing plazmic print problem program programming project recursion scanner screen server set sharepoint size smart sms socket sort sortedmaps sql string swing test textfield threads time transfer tree unlimited webservices windows






