| | |
Creating Login
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
java Syntax (Toggle Plain Text)
public class AccountInfo { //private String userName; private int pictureInput; private int userID; private GUI gui; private ArrayList userName; private ArrayList password; public AccountInfo() { gui = new GUI(); userName = new ArrayList(); password = new ArrayList(); } public void setUsername() { userName.add(gui.getName()); } public void setPassword() { password.add(gui.getName()); } }
Heres my AccountInfo class
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
Heres some more of my improved Gui.
'
I still am struggling to do this all I gave picture id though.
'
I still am struggling to do this all I gave picture id though.
java Syntax (Toggle Plain Text)
//createAccountBtn pressed createAccountBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { userName = userNameInput.getText(); userID = userName + passWord; userBox.addItem(userName); } }); //accountPicture1 pressed accountPicture1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { passWord = "1"; } }); //accountPicture2 pressed accountPicture2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { passWord = "2"; } }); //accountPicture3 pressed accountPicture3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { passWord = "3"; } }); //accountPicture4 pressed accountPicture4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { passWord = "4"; } }); //accountPicture5 pressed accountPicture5.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { passWord = "5"; } }); //loginBtn pressed loginBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { loginPanel.setVisible(false); workSpacePanel.setVisible(true); } });
•
•
•
•
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.
2. For storing the username vs. ID mapping use HashTable/Map.
3. The pictures: I don't know why you need to store any information abt them at all. See my previous posts. They're static info and can be just kept to the UI component. Don't de/serialize them.
Once your login page comes, the user would type a username in the control u're using for username, also he'll select/click the picture he wants, on this click you set passWord (as you've coded).
On click of the create account button you just add this username password combination to your HashMap object.
When you're exiting from the process, you serialize (write) the HashMap to a flat file using Properties class (just copy all data from HashMap to Properties class and use it's method to write to file).
At next startup of your process you'll have this process so in main() or somewhere during initialization you create Properties object using name of the the file to which you had serialized, Properties class will read all data.
Now you copy this data from Properties file to HashMap and you're back in business.
On click of the create account button you just add this username password combination to your HashMap object.
When you're exiting from the process, you serialize (write) the HashMap to a flat file using Properties class (just copy all data from HashMap to Properties class and use it's method to write to file).
At next startup of your process you'll have this process so in main() or somewhere during initialization you create Properties object using name of the the file to which you had serialized, Properties class will read all data.
Now you copy this data from Properties file to HashMap and you're back in business.
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
Wow you make it seem so easy. Just add Username and Password to hashmap aye. java Syntax (Toggle Plain Text)
private HashMap userInformation; //createAccountBtn pressed createAccountBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { userName = userNameInput.getText(); //userNameInput.setText(userName); userBox.addItem(userName); //AccountInfo.aUserID.add(UserID); //userID = userName + passWord; //userIDs.add(userID); userInformation.put(userName,passWord); //userName = null; //passWord = null; } });
Thanks for you help once again. I don't thing you can explain it any simpler. I will make sure to listen to what you said but I right now I really gotta understand hashmaps better
. >> So I should use store?
>> and then load to login?
Yes.
Overall flow would be:
>> and then load to login?
Yes.
Overall flow would be:
- From main() you create your UI elements.
- Add all actionListners().
- Create the Properties object and call load() with name of the file that you used for storing the data (in last run).
- Copy all data from this Properties object to a HashMap.
- On click of one of the pictures you set the password variable (as you're doing).
- On click of create account button, pickup the username/password and see if it's already existing in the HashMap. If yes, it's an error.
- On click of Login button pickup the username/password and see if user name is already existing in the HashMap. If not it's an error, if yes see that password (ID) matches.
- At the end before exiting from main(), copy all data from HashMap to a new Properties object and call store() with the file name.
•
•
Join Date: Mar 2007
Posts: 27
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
public class User { private String userName; private String password; private String accountInfo; public User() { //accountInfo = new ArrayList(); } public void setPassword(String pass) { password = pass; } public void setUsername(String user) { userName = user; } public void setAccountInfo() { accountInfo = password + userName; } public void saveAccountInfo() { try { File dir = new File("H:/SDI/MileStone3/" + userName); dir.mkdir(); FileOutputStream fOut = new FileOutputStream("H:/SDI/MileStone3/" + userName + "/accountInfo.dat"); ObjectOutputStream oOut = new ObjectOutputStream(fOut); oOut.writeObject(accountInfo); oOut.close(); System.out.println("Account info saved"); } catch(Exception e) { System.out.println("Error! High Scores not saved"); e.printStackTrace(); } } public void checkInfo() { /** //attempt to restore the high scores try { FileInputStream fIn = new FileInputStream("accountInfo.dat"); ObjectInputStream oIn = new ObjectInputStream(fIn); accountInfo = (String) oIn.readObject(); System.out.println("High Scores restored successfully!"); oIn.close(); userName.compareTo(password); } catch(FileNotFoundException e) { System.out.println("No file found"); } catch(ClassNotFoundException e) { System.out.println("Class not found!"); e.printStackTrace(); } catch(IOException e) { System.out.println("IO Error!"); e.printStackTrace(); } } **/ userName.compareTo(password); } }
Java Syntax (Toggle Plain Text)
//GoCreateAccount button pressed goCreateAccount.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { createAccountPanel.setVisible(true); loginPanel.setVisible(false); } }); //GoLogin button pressed goLogin.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { createAccountPanel.setVisible(false); loginPanel.setVisible(true); } }); //accountPicture1 pressed accountPicture1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("1"); } }); //accountPicture2 pressed accountPicture2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("2"); } }); //accountPicture3 pressed accountPicture3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("3"); } }); //accountPicture4 pressed accountPicture4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("4"); } }); //accountPicture5 pressed accountPicture5.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("5"); } }); //loginBtn pressed loginBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { loginPanel.setVisible(false); workSpacePanel.setVisible(true); } }); //loginPicture1 pressed loginPicture1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("1"); } }); //loginPicture2 pressed loginPicture2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("2"); } }); //loginPicture3 pressed loginPicture3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("3"); } }); //loginPicture4 pressed loginPicture4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("4"); } }); //loginPicture5 pressed loginPicture5.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setPassword("5"); } }); //createAccountBtn pressed createAccountBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { info.setUsername(userNameInput.getText()); userBox.addItem(userNameInput.getText()); info.setPassword(pass); info.setAccountInfo(); info.saveAccountInfo(); createAccountPanel.setVisible(false); loginPanel.setVisible(true); } }); //loginBtn pressed loginBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { pass = (String) userBox.getSelectedItem(); info.setUsername(pass); info.checkInfo(); } }); //logoutBtn pressed logoutBtn.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { loginPanel.setVisible(true); workSpacePanel.setVisible(false); } }); } }
![]() |
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
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary block bluetooth character chat class client code component consumer csv database desktop eclipse error fractal ftp game givemetehcodez graphics gui html ide image input integer j2me japplet java javaarraylist javac javaee javaprojects jmf jni jpanel julia linked linux list loop mac map method methods mobile netbeans newbie number objects online oriented panel print printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner screen se server set size sms sort sql string swing template test threads time title tree tutorial-sample ubuntu update windows working





