Login form code in dot net IDE – vikramnvp11

This code is for beginners. Those who are new to coding.

Copy paste of code is disabled on this site. If you do copy paste of code, few days later, you will not remember anything. Therefore type the code in IDE manually. Am sure you will remember some code in your head.

This is a simple login form code using try catch block. Try to understand the flow of the code.

 try{
            String uname=jTextField1.getText();
            char[] pwd=jPasswordField1.getPassword();
            String password=new String(pwd);

	    if((uname.equals("")&&(password.equals(""))))
	    {
                JOptionPane.showMessageDialog(null,"Enter username & password..!!");
            }
            else if((uname.equals("")))
	    {
                JOptionPane.showMessageDialog(null,"Enter username...!!");
        
            }
	    else if((password.equals("")))
	    {
		JOptionPane.showMessageDialog(null,"Enter password...!!");
	    }
	    else

	    if((uname.equals("vikram")))
	    {
		if((password.equals("star")))
	        {
                  	JOptionPane.showMessageDialog(null,"Login Successful");
                }
                else
	        {
        
	                JOptionPane.showMessageDialog(null,"invalid password");
                }
            }
	    else
	    {
		JOptionPane.showMessageDialog(null,"invalid user");
	    }
            
    }
    catch(HeadlessException e)
    {
            System.out.println(e.getMessage());
    }

Just design a simple form. It should contain one name filed, password field and one submit button.

All conditions nested inside the try catch block, to catch any exception that arise.

Initially user name and password field is verified. If both of them are empty, “Enter username & password..!!” message will displayed.

Check out my other posts