Results 1 to 4 of 4
- 04-11-2011, 11:27 PM #1
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
New to GUI. Logging in with Password and username
I have tried and tried, but I am getting nowhere by myself. Basically There is three different types to login to the program; an admin, student or faculty. As of right now I am trying to get the easiest out of the way, which I would think would be admin (ID is admin Password is admin). Student and faculty are in an array with their own passwords and IDs. This is what I have as of right now. Please excuse the mess, since this is my first ever time to mess with GUIs.
I took parts form a tutorial and it confused me even more. when I tryJava Code:public Application() { super("Log on"); this.setSize(300, 300); setLayout(new FlowLayout()); this.setVisible(true); currentUserObject = null; userDatabase = new Person[20]; courseDatabase = new Course[10]; numberOfUsers = 0; numberOfCourses = 0; keyboard = new Scanner(System.in); addRecords(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel namePanel = new JPanel(); JPanel passwordPanel = new JPanel(); namePanel.setLayout(new GridLayout(4,4)); namePanel.setLayout(new BorderLayout()); namePanel.setBackground(Color.WHITE); passwordPanel.setLayout(new GridLayout(4,4)); passwordPanel.setLayout(new BorderLayout()); passwordPanel.setBackground(Color.WHITE); endButton = new JButton("Exit"); endButton.addActionListener(this); login = new JButton ("Login"); clear = new JButton("Clear"); clear.addActionListener(this); name = new JTextField (20); name.addActionListener(this); JLabel nameLabel = new JLabel("Enter your User Name here:"); namePanel.add(nameLabel); password = new JPasswordField (20); password.addActionListener(this); JLabel passwordLabel = new JLabel("Enter your Password here:"); passwordPanel.add(passwordLabel); add(namePanel); add(name); add(passwordPanel); add(password); add(login); add(endButton); add(clear); } public void actionPerformed(ActionEvent e) { if(e.getSource() == clear) { name.setText(""); password.setText(""); } if (e.getSource()== endButton) { System.exit(0); } if (e.getSource()==login) { char [] ID, pw; pw = password.getPassword(); if (?????) { JOptionPane.showMessageDialog(controllingFrame, "Success! You typed the right password."); } else { JOptionPane.showMessageDialog(controllingFrame, "Invalid password. Try again.", "Error Message", JOptionPane.ERROR_MESSAGE); } } // please go over the presentations and example programs that are posted on webct. } private static boolean isPasswordCorrect(char[] input) { boolean isCorrect = true; char[] correctPassword = {'b', 'u', 'g', 'a', 'b', 'o', 'o'}; if (input.length != correctPassword.length) { isCorrect = false; } else { isCorrect = Arrays.equals (input, correctPassword); } return isCorrect; }
My question is then this. How would I go about logging in as an admin?
- 04-11-2011, 11:32 PM #2
Senior Member
- Join Date
- Feb 2010
- Posts
- 128
- Rep Power
- 0
The way I would do, is to assign letter to the id. Admin could be: a1234, Student: s1234, Faculty: f1234. When logging, check the first character and depending of which char it is check matching array for password.
Hope this helpsMeasuring programming progress by lines of code is like measuring aircraft building progress by weight.
- 04-11-2011, 11:35 PM #3
- 04-11-2011, 11:39 PM #4
Member
- Join Date
- Apr 2011
- Posts
- 7
- Rep Power
- 0
OOPS. That is an excellent question! I feel like a really stupid man. That could be the exact reason. I'll report back here in a little bit.
Okay, I got it to actually respond to the tutorial password. I don't think I worded the whole login ID/Password problem thing very well, so I will do it again. In this program we already have set logins. For instance, to login into an admin you must type the ID and Password as admin. If you wanted to log into a student you pick from this list:
The first number (which is bolded) is the ID. The last number (which is underlined) is the Password. A login screen will appear. When you type in your ID and password you should be sent to a menu that has different options. For example:Java Code:private void addRecords() { // Create Users userDatabase[numberOfUsers++] = new Student("[B]92038201[/B]", "Ilyas", "Uyanik", "Computer Science", "[U]1956[/U]", 2, 1);//0 userDatabase[numberOfUsers++] = new Student("[B]20483002[/B]", "Joseph", "Mathew", "Computer Science", "[U]1234[/U]", 3, 1);//1 userDatabase[numberOfUsers++] = new Student("[B]26023923[/B]", "Suzan", "Pink", "Computer Science", "[U]2342[/U]", 3, 1);//2 userDatabase[numberOfUsers++] = new Student("[B]34532343[/B]", "Amy", "Yellow", "Computer Science", "[U]4533[/U]", 1, 1);//3 userDatabase[numberOfUsers++] = new Student("[B]78643546[/B]", "George", "Black", "Computer Science", "[U]0495[/U]", 4, 1);//4 userDatabase[numberOfUsers++] = new Student("[B]45345753[/B]", "Fatih", "Haberdar", "Computer Science", "[U]5478[/U]", 1, 1);//5 userDatabase[numberOfUsers++] = new Student("[B]23748967[/B]", "Murat", "Erdogan", "Computer Science", "[U]9043[/U]", 2, 1);//6 userDatabase[numberOfUsers++] = new Student("[B]32946262[/B]", "Sam", "Blue", "Computer Science", "[U]3241[/U]", 4, 1);//7 userDatabase[numberOfUsers++] = new Faculty("[B]52037101[/B]", "Hakan", "Haberdar", "Computer Science", "[U]1267[/U]", 70000.0, 2);//8 userDatabase[numberOfUsers++] = new Faculty("[B]30293102[/B]", "Bill", "Brown", "Computer Science", "[U]7810[/U]", 100000.0, 2);//9 userDatabase[numberOfUsers++] = new Faculty("[B]10132103[/B]", "John", "White", "Computer Science", "[U]3724[/U]", 60000.0, 2);//10 userDatabase[numberOfUsers++] = new Faculty("[B]32546104[/B]", "Ayse", "Red", "Computer Science", "[U]2938[/U]", 80000.0, 2);//11 userDatabase[numberOfUsers++] = new Faculty("[B]98232105[/B]", "Emre", "Charu", "Computer Science", "[U]2302[/U]", 83000.0, 2);//12
(I'll convert that into GUI later).Java Code:System.out.println("------------+------------"); System.out.println("Please make a selection:"); System.out.println("A - Add Course"); System.out.println("S - Add Student"); System.out.println("F - Add Faculty"); System.out.println("L - List Users"); System.out.println("C - List Courses");
This was given to us at the bottom, and I am not sure if we are supposed to use this for the GUI.
Would I use the login() in my GUI, or do I make separate isPasswordcorrect functions? If I were to make separate isPasswordCorrect functions how would I access the student and faculty array?Java Code:private void login() { boolean userVerified=false; int attemptNumber =0; String ID, password; do { System.out.print("ID :"); ID = keyboard.next(); System.out.print("Password :"); password = keyboard.next(); attemptNumber++; if( ID.equals("admin") && password.equals("admin")) { showAdminMenu(); userVerified = true; } else { // Faculty/Student for(int i=0; i<numberOfUsers;i++) { if( userDatabase[i].validation(ID, password) ) { currentUserObject = userDatabase[i]; if(userDatabase[i].getUserType()==1 ) { showStudentMenu(); userVerified = true; } else if(userDatabase[i].getUserType()==2 ) { showFacultyMenu(); userVerified = true; } } } if( !userVerified && attemptNumber<3) { System.out.println("User not found, please try again."); } } } while (!userVerified && attemptNumber<3 ); if( !userVerified ) { System.out.println("None of the IDs/passwords you entered matches our records."); System.exit(attemptNumber); } }Last edited by slitka; 04-11-2011 at 11:58 PM.
Similar Threads
-
how to link url with username and password
By gb.rashu in forum JavaServer Pages (JSP) and JSTLReplies: 13Last Post: 08-12-2010, 03:12 PM -
password username and databases
By chalo in forum JCreatorReplies: 0Last Post: 12-02-2008, 08:11 AM -
username password verification
By bheezee in forum JDBCReplies: 0Last Post: 11-25-2008, 06:55 PM -
Help, created a username and password box
By cachi in forum AWT / SwingReplies: 1Last Post: 08-07-2007, 04:21 AM -
JTextFields with username & password.
By Eric in forum AWT / SwingReplies: 2Last Post: 07-01-2007, 11:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks