Login Applet

Hi,
I m new to Java and was working on creating a login Applet. I have put event handler on submit button . it will check and validate the user name & password with hardcoded one. to login user name is "test' and password is "password".
if i try with some other user name, it gives message "Wrong user...." as per logic. But when i try to connect with "test" it still gives same error.
in event handler it is going in else section where i am comapring the user name with "test" however, it should go in true section and validate password.
given below is my login applet code.. will anybody help me where i am wrong.
public class login extends java.applet.Applet
     Button submit = new Button("Connect to Server");
     TextField user = new TextField(20);
     TextField pass = new TextField(20);
     Label result_label = new Label("Pls input User Name and Password to Login");
     String user_name = "";
     String pass1 = "";
     public void init()
          user.setEditable(true);
          pass.setEditable(true);
          String result = "";
          GridBagLayout grid = new GridBagLayout();
          GridBagConstraints cons = new GridBagConstraints();
          setLayout(grid);
          setFont(new Font("Times New Roman",Font.PLAIN,12));
          setBackground(Color.orange);
          setForeground(Color.black);
          cons.weightx = 1.0;
          cons.weighty = 0.0;
          cons.anchor = GridBagConstraints.CENTER;
          cons.fill = GridBagConstraints.NONE;
          cons.gridwidth = GridBagConstraints.REMAINDER;
          add(new Label("User Name: "));
          grid.setConstraints(user, cons);
          add(user);
          add(new Label("Password: "));
          grid.setConstraints(pass, cons);
          add(pass);
          result_label.setFont(new Font("Times New Roman", Font.BOLD, 12));
          result_label.setForeground(Color.blue);
          grid.setConstraints(result_label, cons);
          add(result_label);
          grid.setConstraints(submit, cons);
          add(submit);
          cons.weighty = 1.0;
          show();
     public boolean handleEvent(Event evt)
          if (evt.target ==user)
               char c = (char) evt.key;
               if (c == '\n')
                    user_name = user.getText();
                    return(true);
               else
                    return(false);
          if (evt.target == pass )
               char c = (char) evt.key;
               if (c == '\n')
                    pass1 = pass.getText();
                    return(true);
               else
                    return(false);
          if (evt.target == submit)
               char c = (char) evt.key;
               if ( c == '\n')
                    double i;
                    i = 1;
                    result_label.setText("Verifing ..............");
                    do { i = i + 0.0001; }while (i <= 8000);
                    user_name = user.getText();
                    if (user_name == "test" )
                         pass1 = pass.getText();
                         if (pass1 == "password")
                              result_label .setText("Login Sucessfull!!! Connecting to Server...");
                              return(true);
                         else
                              result_label .setText("Invalid Password...");
                              return(false);
                    else
                         String text1 = "Invalid user " + user_name + " Access Not allowed";
                         result_label.setText( text1);
                         return(false);
               else
                    return(false);
          else
          {     return(false);
     public void destroy()
          try
               //cons.close();
          catch (Exception e)
               e.printStackTrace();
               System.out.println(e.getMessage());
}

Use the equals() methods to compare strings.
if(pass1.equals( "password"))

Similar Messages

  • A java login applet

    has anyone created a java login applet (source code) that I could use as an example when I attempt to make one. Thank you.

    What are you logging into? What credentials need to be there?
    Normally in these (sometimes unforgiving) forums you need to post a question, some code, a problem, and then the many fine folks here will help you find the answer.
    What part of your code are you having problems with?
    For tutorials check out the sun tutorials. They are very good.
    Peace

  • Login applet digital signature

    Hello,
    The digital signature of the login applet is only valid from: Wed Sep 01
    02:00:00 CEST 2004 to Fri Sep 02 01:59:59 CEST 2005, so I get a warning
    when I login via Webbrowser. I'm using SGD EE 4.1. Is there an update
    available, or do I have to migrate to 4.2?
    Sincerely,
    Robert Niess

    I am also having a problem with the SGD login applet signature being outdated? Is there any patch to this issue? It may be related to another issue I am having.

  • Help creating a login applet with JDBC

    Hi, I'm trying to create a login applet using a table from a database (created with Microsoft Access). The bottom line is that I have very little knowledge of ActionListeners. I do know some things about JDBC, but most of it is through notes and lots of reading. I was wondering how to go about looking through a table (with two columns, user and password), to see if it matches what is typed into a JTextField and a JPasswordField. Just a sample piece of code would be helpful. Thank you very much in advanced. Also, I have the GUI done for what I need, just no ActionListeners or JDBC functionality implemented. Here it is:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.sql.*;
    public class login extends JFrame /*implements ActionListener*/ {
         private Container container;
         private GridBagLayout layout;
         private GridBagConstraints gbc;
         public login()
              super("Login");
              setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            setSize(300,130);
            setLocationRelativeTo(null);
              container = getContentPane();
              layout = new GridBagLayout();
              container.setLayout(layout);
              gbc = new GridBagConstraints();
              labelUser = new JLabel("Username:");
              gbc.insets = new Insets(2,2,2,2);
              container.add(labelUser, gbc);
              textUser = new JTextField(15);
              gbc.gridx = 1;
              gbc.gridwidth = 3;
              container.add(textUser, gbc);
              labelPassword = new JLabel("Password:");
              gbc.gridy = 1;
              gbc.gridx = 0;
              gbc.gridwidth = 1;
              container.add(labelPassword, gbc);
              textPassword = new JPasswordField(15);
              gbc.gridx = 1;
              gbc.gridwidth = 3;
              container.add(textPassword, gbc);
              button1 = new JButton("Login");
              gbc.gridy = 2;
              gbc.gridx = 1;
              gbc.gridwidth = 1;
              container.add(button1, gbc);
              button2 = new JButton("Cancel");
              gbc.gridx = 2;
              container.add(button2, gbc);
         public static void main(String args[]) {
            new login().setVisible(true);
        private JButton button1, button2;
        private JLabel labelUser, labelPassword;
        private JTextField textUser;
        private JPasswordField textPassword;
    }Thank you again in advanced.

    Sir,
    Much of your question makes middling sense to me. You say applet but you have JFrame for example. I would caution you right now an applet with access for a DB is asking for trouble. Never minding the various security issues Access is not really intended for this sort of operation.
    Now none of that actually seems to be your question but I just thought I'd address that before you go too far down a road fraught with peril.
    As far as what I think you are asking assuming our table looks like this.
    tblUser
    username VARCHAR (access text field) primary key
    password VARCHAR (again known in access as text)then the code would look something like this...
    Connection c; //create your connection
    PreparedStatement ps = c.prepareStatement("SELECT username FROM tblUser WHERE username=? AND password=?");
    ps.setString(1,usernameVariable);
    ps.setString(2,passwordVariable);
    ResultSet rs = ps.executeQuery();
    if(rs.next()){
      // login successful
    }else{
      // login failed!
    rs.close();
    ps.close();
    c.close();Also duffymo will be unhappy if I don't mention that you will really want to give second thought to mixing your database code with your GUI code. Please take a gander through http://java.sun.com/blueprints/patterns/MVC.html
    Sincerely,
    Slappy

  • Login Applet Help

    Hello
    I am trying to write a applet that allows me to login to a particular page on my site. I am new to java and have looked some books on the subject. I thought I would be able to manage it myself but I cant for the life of me do it.
    Here is the code I have written:
    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    <applet code="pass" width=300 height=80>
    </applet>
    public class pass extends Applet implements ActionListener{
         Label lbl1;
         Button btn1;
         TextField txa1;
         public void init(){
              lbl1= new Label("Please enter your password!");
              btn1= new Button("ok");
              txa1= new TextField("",20);
              add(txa1);
              add(btn1);
              add(lbl1);
              btn1.addActionListener(this);
         public void actionPerformed(ActionEvent ae){
              if(txa1 == 'will'){
              lbl1.setText("Password Accepted");
              //**GOTO A CORRECT URL
              else{
              lbl1.setText("Password Incorrect");
              //**GOTO REJECT URL
    How can I get it to check the password entered? Also how the hell do get it to go to a URL???
    Any help would be appreciated.
    Regards
    Jimmy

    (1) Use the getText() method of TextField to get the data typed into the TextField. Returns a String
    (2) Use the equals() method of class String to compare the String returned by the above with the password
    (3) Use the Applet method getAppletContext() to return a reference to the browser.
    (4) Use the AppletContext method showDocument() to redirect the browser to a new page.
    public void actionPerformed(ActionEvent ae)
    if(txa1.getText().equals("will"))
        lbl1.setText("Password Accepted");
        try
            URL url = new URL("http://www.thePageIwantToView.com");
            getAppletContext.showDocument(url);
        catch (MalformedUrlException muex)
           System.out.println(muex.toString());

  • How to Debug multiple Applets in a IDE

    Hi,
    I am relatively new to Java. At work, I have a client-server style application where applets are deployed to the clients in an html page.
    Background:*
    The sequence is something like this:
    - Client goes to the relevant url
    - The returned html page has an embedded login applet
    - Upon successful login, an html page is returned that has two embedded applets
    - On the client side, navigation buttons within the applets take them to other applets
    On the server there is an application running that listens to the relevant socket (that the client sends data to) and sends out appropriate responses and data.
    Question:*
    How do i setup this system in any IDE (any IDE is ok with me) so that i can do the following:
    - Step through and debug the applets (appletviewer doesnt work because it seems to work with independent applets only. In my case, all the applets have relationships among them. eg. unless the login applet successfully completes, the other applets cannot work... etc)
    - Visually view / edit existing applets UI (something like a WYSIWYG tool)
    Thank you so much.
    schinni

    Hi,
    I am actually, working in an applet too, and I also need to debug it. With Eclipse you will easily get it, just click with Right button on the project�s name and choose: Debug As-> Java Applet. You can arrive also by: Debug As-> Open Debug Dialog. At the end you will have a window where you will be able to add the applet parameters in the Parameters tab. Finally you only have to set breakpoint (double click in the left side of any code line) and with F5, F6 and F7 you will get the absolute control. I don't think you've problems even you run multiple applets.
    Hope it helps you (sorry for my poor English).

  • Code Signing certificate expired

    Hello,
    I please need an information about SGDEE 4.1 login applet: it seems
    applet code signing certificate was expired on September 2, 2005.
    I have no problem (after I deleted all expired root certificates from
    local client repository) with Internet Explorer 6SP1, but Mozilla Firefox
    always prompt me a warning with this contents:
    Serial:     
    [62374265099632433790334794162326322759]
    Issuer:
    N=VeriSign Class 3 Code Signing 2001 CA,
    OU=Terms of use at https://www.verisign.com/rpa (c)01,
    OU=VeriSign Trust Network,
    O="VeriSign, Inc."
    Valid From: Wed Sep 01 02:00:00 CEST 2004,
    To: Fri Sep 02 01:59:59 CEST 2005
    Subject:
    CN="Tarantella, Inc.",
    OU=Digital ID Class 3 - Netscape Object Signing,
    O="Tarantella, Inc.",
    L=Santa Cruz,
    ST=California,
    C=US
    Thank you very much in advance,
    Best Regards,
    Valerio Morozzo

    I know this is an older post, but it helped me find out how to make the migration procedure for native installer. I tried it with self signed certificate created by ADT tool and everything went fine.
    But now, we obtained a commercial AIR signing certificate from Thawte and the process failes in step 3) ADT saying
    'Certificate in PATH_TO_P12 could not be used to sign setup.msi' on Windows.
    On mac, it says that signing native installer on OSX is not supported, so I skipped the signing option in step 3) and it worked fine.
    I can skip the signing option on Windows as well and the process succeeds, but running the installer on machines with previous versions of application results in "Installer mis-configured' error message - the same error as if the migration process was not applied.
    I already contacted Thawte if it is a certificate issue, reply from them was 'AIR certificate can only sign .air applications'. But when I build a native application directly from FlashBuilder and sign it with the Thawte certificate the whole process seem to succeed. The application can be installed on machines without previous version of the application. Those who already have the older version get the 'Installer mis-configured' error message.
    I want to mark out again, that the same process but with a self signed certificate created with ADT, is successfull and the application can be installer as an update on machines with older version of the app. So I assume the workflow is correct.
    Any ideas? Or somebody having the same issue?
    Thanks

  • Create image button?

    Is it possible to have an image as a button in an applet? For example, creating a login applet, that has two buttons, login and reset. I would like to have those two buttons as a image and still function as a button. How do I do it?

    The brute force way, in AWT, would just be to create a Canvas, have its paint() method draw the image, and add a MouseListener to it.
    But I'll bet in Swing (and maybe in AWT as well) there's a simpler way -- maybe registering an image with a button.
    This isn't really an applet question. It's a GUI question. Ask on the AWT or Swing forums. You're probably better off using Swing.

  • How to disable Copy/Paste to a field in Siebel 7.8

    Hi Gurus,
    Is there a way to disable paste into a certain field in Siebel 7.8?There is a way to do that in normal HTML but is it possible in Siebel.

    One option that comes to mind is to intercept the HTML that is generated for the field on the applet and append to it with the HTML/Javascript that would prevent the pasting.
    For example on the login applet we put some code in capture the enter key since it did not work out of the box.
         if (ControlName == "Password" && Property == "FormattedHtml")
              //onkeypress='JavaScript:null'
              var iOnKeyPressLoc = HTML.indexOf("onkeypress='JavaScript:null'");
              if (iOnKeyPressLoc > 0)
                   //.... REMOVED FOR DISPLAY ....               
                   HTML = sLeftHTML + " " + sMidHTML + " " + sRightHTML;
         }

  • SGD 5.0 and Java 7u45

    A member of our group started using Java 7 update 45 and cannot go to our site running SGD 5.0 with IE. He switch to Firefox which allowed him to contiue after telling us the cert is not valid. However it say it will be blocked in the future java updates because the JAR file manifest does not contain the Permisions attribute.
    Do you plan to have for such a JAR file?  This site is a POC so we have a self signed cert. I was planning on buying a cert if we move to a production machine.

    There appears to be 3 different issues:
    IE Login/Applet Launch Issue
    Self-Signed Certificate Warning - This is normal and expected behaviour of the applet.
    JAR RIA Attribute Warning.
    For 1,3 please contact support via support.oracle.com, and they will be able to advise appropriately.
    You may also want to review the MOS documentation on SGD and JRE7 https://support.oracle.com/oip/faces/secure/km/DocumentDisplay.jspx?id=1487307.1 in regard to point 1.

  • Allow third-party browser extentions

    Hello,
    After upgrading to Java 7 up21, I now need to enable the Internet Explorer security option to "Allow third-party browser extensions" to allow the Java login applet at the DCO Jabber site. How can I increase verbose logging in Java to help explain what has caused this change? Thanks.
    - Dave

    i have the same problem - someone please help

  • Tarantella/SGD Testing/Monitoring Utility

    I was wondering if anyone could recommend a tool to test the full lifecycle of a login sequence using Tarantella WebTop from a browser session. We can monitor if the web server is displaying web-pages, but we wanted to find out if anyone could think of a tool that could:
    1. Goto https://<URL>/index.html
    2. Click on the Login link
    3. Wait for the splash screen to show up
    4. Wait for the login applet to show up
    5. Enter in a user ID and password
    6. Wait for the TTA webtop
    7. Click on a TTA object link, like an xterm
    8. Type in a command (to call a heartbeat script)
    9. Type exit out of the xterm
    10. Hit logout on the TTA webtop
    We are mostly indifferent to running the tool on a Windows box or a Unix box, but a Unix box would be preferred
    Ideally we'd like an open source tool as well, but that is a secondary concern at this point.
    Thanks in advance for any ideas/help
    C

    If you can run the 'heartbeat script' directly in the object (as opposed to starting it inside the terminal), you could do this with Selenium (http://seleniumhq.org/). If you need to manually start the app, a GUI test tool such as QuickTestPro will be required.

  • Login screen before the actual application in an applet.

    Hi all,
    I'm really looking for a tutorial or something but I haven't managed to get the wording right in my google searches.
    I have an applet that is communicating with a server. Before getting access to the applet as such I would like a login screen. This is not there for the purposes of security but rather which server to work against.
    I'm having a bit of problem with the GUI - what would be the best way of doing this?
    When you hit the webpage and the applet loads there will be 3 test fields and 3 input boxes - one being a password box. and finally a OK button.
    The OK button will call a function I already have that will verify that the credentials are OK and pass back a yay or nay - if I get a nay I want to stay on the login page.
    If I get a yay - and this is where I don't know what to do. I want a complete GUI redraw of the new components.
    I have tried to put all components into the one window and hide-and-show them as required but this just turns into a complete mess. I have the second window already - and I'm quite happy with it so I really want a brand new login window and switch from one to the other without having to resort to the messy hack I'm currently using.
    I'm sure I'm missing something pretty basic here so if someone could please guide me towards a tutorial I'd appreciate it.
    thanks,
    Dan

    That's exactly what I was looking for.
    thanks!

  • Applet Login Screen

    Hi everyone.
    I decided to make an applet which has a login screen like "User Name" & "Password" and below there are 2 buttons "cancel" and "login"... Anyway the real problem is i have no idea about the process after log in the program...
    How can i make a load screen and start the interface at the same window...
    Just like :
    1-) i enter the name and pass then click the login button
    2-) A load screen appears
    3-) After load screen my interface shown in the screen
    Has anyone have a tutorial or idea about this problem?
    i'll be really appreciate if you'll help me!
    Thanks.

    I try to make a program for my programming lessonn and the program has an user interface. But first the user log in to the program... So firstly the log in panel must appear. Then when you logged in correctly , the applet must load the interface of the program... (there may be a loading screen shows up )
    just like an email provider there's a login panel and the user interface but all needs to be applet.

  • Proxy Login Request on Java applets

    • 10.4.5 Client
    • Windows 2.3k ISA 2005 Proxy Server
    • Users' fileserving to Win2.3k - ADmitMac for AD integration
    The client is a test machine on which I build campus master NetInstall images. In my testing procedures I've come across a bizarre problem with Java in the browsers (IE, Safari, & FireFox).
    We use ISA proxy server with web filtering, and users must authenticate to the proxy. On a new user's first use of any browser, the proxy username & password are requested, and the Add to Keychain checkbox is available. If the user checks the box, no further proxy login requests are made; the user's Keychain is updated with the proxy information.
    On pages with Java applets, however, each and every applet will ask for a proxy login, but the login window does not offer a Add to Keychain checkbox! If a page has 15 applets on it, the user will be asked 15 times to authenticate against the proxy.
    Naturally, this is a BIG problem, especially when several of the sites our teachers use in classes and labs contain many Java applets.
    On the web, there is almost nothing concerning setting up Java with proxy servers, as all Apple Java from v. 1.4.2 onwards picks up proxy information from the system's network settings.
    On the Apple Developer site, Tech Note QA1263 demonstrates a way of setting HTTPS proxy settings by entering text strings in the 1.3.1 and 1.4.1 Plugin Settings apps Java Runtime Parameters. The same capability exists in the J2SE 5.0 Java Preferences app, too. Unfortunately, the Java applets do not use HTTPS, so far as I can tell, so this remedy is useless.
    Any clues I can pursue? Any help or fixes?
    Thanks in advance!
    Derek I Smith
    Systems & Network Admin
    Riverdale Country School
    www.riverdale.edu
    eMacs,g4s,QSs,B/Ws,iMacs,G5,G5 XServe, etc   Mac OS X (10.4.5)  

    After some more research with the J2SE 5.0 Java Preferences app, I turned on the Java console, booted Safari and went to my favorite Java applet - babynamewizard. This is the output of the console log. From what I can glean, the plug-in sees the proxy server settings as it should, and reports them.
    In addition, the J2SE 5.0 Java Preferences app allows you to turn off all security settings. No change in behavior.
    The Log:
    Java Plug-in 1.5.0
    Using JRE version 1.5.0_05 Java HotSpot(TM) Client VM
    User home directory = /Users/admin
    network: Loading user-defined proxy configuration ...
    network: Done.
    network: Loading proxy configuration from Netscape Navigator ...
    network: Done.
    network: Loading manual proxy configuration ...
    network: Done.
    network: Proxy Configuration: Manual Configuration
    Proxy: http=pcproxy.riverdale.edu:8080,https=pcproxy.riverdale.edu:8080,ftp=pcproxy.ri verdale.edu:8080,gopher=pcproxy.riverdale.edu:8080,socks=pcproxy.riverdale.edu:8 080
    Proxy Overrides:
    basic: Cache is enabled
    basic: Location: /Users/admin/Library/Caches/Java/cache/javapi/v1.0
    basic: Maximum size: unlimited
    basic: Compression level: 0
    c: clear console window
    f: finalize objects on finalization queue
    g: garbage collect
    h: display this help message
    l: dump classloader list
    m: print memory usage
    o: trigger logging
    p: reload proxy configuration
    q: hide console
    r: reload policy configuration
    s: dump system and deployment properties
    t: dump thread list
    v: dump thread stack
    x: clear classloader cache
    0-5: set trace level to <n>
    basic: Referencing classloader: sun.plugin.ClassLoaderInfo@fb6354, refcount=1
    basic: Added progress listener: sun.plugin.util.GrayBoxPainter@dc0e7a
    basic: Loading applet ...
    basic: Initializing applet ...
    basic: Starting applet ...
    network: Connecting http://babynamewizard.com/namevoyager/nametide2.jar with proxy=HTTP @ pcproxy.riverdale.edu/172.16.1.52:8080
    network: Connecting http://babynamewizard.com/namevoyager/nametide2.jar with cookie "s_cc=true; s_sq=%5B%5BB%5D%5D"
    network: Firewall authentication: site=pcproxy.riverdale.edu/172.16.1.52:8080, protocol=http, prompt=ENKI.riverdale.edu, scheme=basic
    basic: User selected: 0
    ~ ~ ~
    The proxy login window appears at this point and I authenticate to the proxy
    The log continues...
    ~ ~ ~
    network: Connecting http://babynamewizard.com/namevoyager/nametide2.jar with proxy=HTTP @ pcproxy.riverdale.edu/172.16.1.52:8080
    basic: Loading http://babynamewizard.com/namevoyager/nametide2.jar from cache
    basic: No certificate info, this is unsigned JAR file.
    network: Connecting http://babynamewizard.com/namevoyager/namedb.zip with proxy=HTTP @ pcproxy.riverdale.edu/172.16.1.52:8080
    network: Connecting http://babynamewizard.com/namevoyager/namedb.zip with cookie "s_cc=true; s_sq=%5B%5BB%5D%5D"
    Columns found: 28
    Num years: 13
    YEAR NAME: 1880s
    YEAR NAME: 1890s
    YEAR NAME: 1900s
    YEAR NAME: 1910s
    YEAR NAME: 1920s
    YEAR NAME: 1930s
    YEAR NAME: 1940s
    YEAR NAME: 1950s
    YEAR NAME: 1960s
    YEAR NAME: 1970s
    YEAR NAME: 1980s
    YEAR NAME: 1990s
    YEAR NAME: 2004
    Num names: 5251
    0 --> 923475.0
    1 --> 915444.0
    2 --> 905002.0
    3 --> 910731.0
    4 --> 915165.0
    5 --> 924335.0
    6 --> 938721.0
    7 --> 940141.0
    8 --> 923814.0
    9 --> 869609.0
    10 --> 848116.0
    11 --> 800666.0
    12 --> 759055.0
    Rank misses: 21
    0.15
    0.4475
    0.395
    0.3425
    0.29000002
    0.23750001
    0.185
    0.48250002
    0.43
    0.3775
    0.325
    0.2725
    0.22
    0.1675
    0.465
    0.4125
    0.36
    0.3075
    0.255
    0.2025
    ~ ~ ~
    The applet runs

Maybe you are looking for