Project 8: Password Applet
Before you begin, create a folder in your Projects Folder called Firstname.LastName.project8. Do a File...Save as this html document into your Project8 folder. Comment out each line or section of java code on anything you do using the /* (insert comments here) and */ symbols.
Intro: Depending on how you do this one, you will probably need to import the java.net package to do this one in addition to java.applet and java.awt.
- Create username and password text fields and a button. Look in java.awt to see how to do it.
- Then you need to add an actionListener() to the button and run actionPerformed() as the method that contains the if/else statement.
- You need to create an if/else statement(inside actionPerformed()) that goes something like this: if (
(usernameField.getText().equals("jonesw")) && (passwordField.getText().equals("smorgasboard")) || (usernameField ...etc. )). The if conditional would run a method that takes the user to the correct website. The else conditional would run a method that would take you to a page that says 'wrong password, etc'. You create the 2 methods. They would both start public void methodname(){ code goes here }.
| UserName | Password |
| jonesw | smorgasboard |
| doej | dingle |
| smithp | pirate |
| rhollj | dufous |
| petersong | yaayaa |
1. Whereas you can write a password authentication script with Javascript, it is not very secure because an experienced webuser can View...Source to break your code. Java password authentication is secure for 2 reasons:- the .class file that contains the "passwords" is compiled into machine code that humans cannot read
- It runs hidden in the Java Virtual Machine, not in the browser or the users computer. Create an applet in the space below that accepts the above 5 username/password combos but rejects all others. The method of acceptance and rejection should be that the correct username/password combination takes the user to one html document and any other combination takes the user to "wrong password" html document. You create the 2 small html documents and put them in your project 8 folder.
Save a copy of your entire folder into the Project 8 Folder on the server. You should have a project8.java file, a project8.class file and a project8.htm file.
Make sure the folder has your Firstname.Lastname.project8 as a title. Open up your project on the server in a browser to make sure it appears the way your want it.