Log In Form Validations

Log In Form Validations

Good Morning
Sir ,I have Created Log in Form with Databse Connectivity and i have took two JTextFields 1)USERNAME
2)password if two Jtextfields are blanks i want to show msg blank Username and Password ,
How I can Do That ,plz Help Me Sir.
View Answers

April 8, 2010 at 11:42 AM

Hi Friend,

Try the following code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
class LoginDemo{
JButton SUBMIT;
JFrame f;
JLabel label1,label2;
final JTextField text1;
final JPasswordField text2;
LoginDemo(){
f=new JFrame();
f.getContentPane().setLayout(null);
label1 = new JLabel();
label1.setText("UserName:");
label1.setBounds(400,50,100,20);
text1 = new JTextField(25);
text1.setBounds(500,50,100,20);
label2 = new JLabel();
label2.setText("Password:");
label2.setBounds(400,80,100,20);
text2 = new JPasswordField(25);
text2.setBounds(500,80,100,20);
SUBMIT=new JButton("Login");
SUBMIT.setBounds(500,110,100,20);

f.add(label1);
f.add(text1);
f.add(label2);
f.add(text2);
f.add(SUBMIT);
f.setSize(1024,768);
f.setVisible(true);
SUBMIT.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
String value1=text1.getText();
String value2=text2.getText();
String user1="";
String pass1="";
try{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st = con.createStatement();
ResultSet res = st.executeQuery("SELECT * FROM login where username='"+value1+"' && password='"+value2+"'");
while (res.next()) {
user1 = res.getString("username");
pass1 = res.getString("password");
}
if(!value1.equals(user1) && !value2.equals(pass1)) {
JOptionPane.showMessageDialog(null,"Incorrect login or password","Error",JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
else if(value1.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Username","Blank",JOptionPane.ERROR_MESSAGE);
}
else if(value2.equals("")){
JOptionPane.showMessageDialog(null,"Please Enter Password","Blank",JOptionPane.ERROR_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"Welcome");
}
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
});

}
public static void main(String arg[]) {
LoginDemo frame=new LoginDemo();
}
}

Thanks









Related Tutorials/Questions & Answers:
Log In Form Validations - Java Beginners
Log In Form Validations  Good Morning Sir ,I have Created Log in Form with Databse Connectivity and i have took two JTextFields 1)USERNAME 2)password if two Jtextfields are blanks i want to show msg blank Username
validations
validations  How to get All Client and server side validations in spring using jsp   Please visit the following link: Spring Validation Example
Advertisements
Validations
the reason.   Here is an example that validates some fields of html form. <html> <h2>Form Validation</h2> <script language... } </script> <form name="form" method="post" onSubmit
validations - Struts
validations  log in page with validations user name must be special character and one number and remining is alphabetes in struts
validations in javascript
validations in javascript  How do you check validations in javascript
Spring Validations
Spring Validations  Hi.. i need code for validations using spring annotations
listbox and textbox validations
listbox and textbox validations  hi, any one please tell me how to set validations for listbox and textboxes using bean classes? thank you...-registration-form-using-jsp.shtml
Validations
Struts validations
the given input from the form. i.e, the given username and password have to be compared
java validations
; if (f.length<20) { alert("Address too short"); return false; } var q=document.retailer.contact_no.value; if (q==null || q=="") { alert...;form name="retailer" action="RetController" onsubmit="return validateForm();">
ModuleNotFoundError: No module named 'validations'
ModuleNotFoundError: No module named 'validations'  Hi, My Python... 'validations' How to remove the ModuleNotFoundError: No module named 'validations' error? Thanks   Hi, In your python environment
ModuleNotFoundError: No module named 'validations'
ModuleNotFoundError: No module named 'validations'  Hi, My Python... 'validations' How to remove the ModuleNotFoundError: No module named 'validations' error? Thanks   Hi, In your python environment
log in
log in  sir i designed one login.jsp page with one form, username,login,and one submit button .if i enter username and password its been verify the mydatabase in in table in the field of username and password while it s correct
select box and text box validations
select box and text box validations  hi, any one please tell me how to set validations for select box and text boxes using bean classes? thank you...-registration-form-using-jsp.shtml
Struts Validations - Framework
Struts Validations  What is the server-side validations exactly? give me on example
form
form   Can I prevent a form from being submitted again
Im not getting validations - Struts
in s-c.xml But Im unable to get validations This is my validation.xml file... ActionForward execute(ActionMapping mapping,ActionForm form,HttpServletRequest request...{ DynaActionForm studForm = (DynaActionForm)form; ActionMessages errors = new
Custom Validations - Struts
Custom Validations  Hi, I am trying to do the custom validations in struts 1.1.That is how can we plug in our own custom validations into Validator ? Can anybody tell me how to do this with a sample example. Thanks
Multiple Validations on jTestFields
Multiple Validations on jTestFields  Hi, I am working on an window application in which I have to validate the data of text fields, like if textbox1... then it should check whether it is valid or not. Unless all the validations
struts validations - Struts
struts validations  hi friends i an getting an error in tomcat while running the application in struts validations the error in server as validation disabled plz give me reply as soon as possible.  Hi friend
ModuleNotFoundError: No module named 'tripleo-validations'
ModuleNotFoundError: No module named 'tripleo-validations'  Hi, My... named 'tripleo-validations' How to remove the ModuleNotFoundError: No module named 'tripleo-validations' error? Thanks   Hi
validations in struts - Struts
validations in struts  hi friends plz give me the solution its urgent I an getting an error in tomcat while running the application in struts validations the error in server as "validation disabled" plz give me reply as soon
Javascript validations problem
Javascript validations problem  i have attached two jsp files 1.sports1.jsp and sports.jsp files Here when i run my sports.jsp file my validation...(); } </script> </head> <body> <FORM name="myform
Struts: validations code to support 2 date foramats - Struts
Struts: validations code to support 2 date foramats  What is the code in validation.xml to support 2 date formats (DD-MM-YYYY & DD/MM/YYYY ) in form. (I'm using struts 1.3
Not retriving the validations from validation.xml - Struts
Not retriving the validations from validation.xml  I have create the file called register.jsp    LoginID: Password: when i
ModuleNotFoundError: No module named 'sqlalchemy_elixir_validations'
ModuleNotFoundError: No module named 'sqlalchemy_elixir_validations'  ...: No module named 'sqlalchemy_elixir_validations' How to remove the ModuleNotFoundError: No module named 'sqlalchemy_elixir_validations' error
spring form validation
spring form validation  how can we validate a web form using spring, try to give an example of the form containing some fields and their validations,ASAP......   Please visit the following link: Spring form validation
Locale Specific Date validations through JavaScript/Ajax...
Locale Specific Date validations through JavaScript/Ajax...  Hi, I....), how to manipulate date validations through JavaScript or Ajax? Thanks... Transitional//EN"> <HTML> <HEAD> <TITLE>Form Validation<
TextField validations
TextField validations
form validation
form validation  how the form validation is done in jsf form using javaScript
Maven Repository/Dependency: io.swagger | swagger-hibernate-validations
Maven Repository/Dependency of Group ID io.swagger and Artifact ID swagger-hibernate-validations. Latest version of io.swagger:swagger-hibernate-validations dependencies. # Version Release Date
Log-in Valdidation
Log-in Valdidation  how to create login validation in jsp
log out
log out  how do i create a log out on a project without it exiting system so it does not reload again
print a form of *
print a form of *   * *** ***** ******* ********* ******* ***** *** *   Post the format properly
Multipage form
Multipage form  I have a multipage form in php with 2 pages wnhen i submit the form data from both the pages should go in database how should i pass teh data from 1st page to 2nd page and then put the entire form data in mysql
jsp form
jsp form  hi sir, one got one got in jsp form after entering the data into the form the data is not saving in the database i will send you code of two forms if dnt understand my problem
submit a form
submit a form  How can we submit a form without a submit button
log 4j
log 4j  what is log4j? can you give me clear information about log4j?   Please go through the following link: log4j Tutorials
log in page
log in page  hi all i want to create a login page in jsp which should...', 'application/x-www-form-urlencoded'); xmlHttp.onreadystatechange = function...;Center> <form name="f1" onsubmit="return call_login();"> <table
Form handling
Form handling  I created a spring project. I created a jsp...;form:form name="loginForm" modelAttribute="loginForm" method="get"> <...;/td> <td> <form:input path="username"/>
Form Validation
Form Validation  Java script validation for checking special characters and white spaces and give an alert.Please help me urgent Thanks in advance
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
<form id=
form id  sir, <form id="reg1" action="../UploadingCtrl" method="post" enctype="multipart/form-data" name="form1"> this action page can't get String tp = request.getParameter("indegrates"). i wrote article upload
how to perform the client side validations to the dropdown list using javascript?
how to perform the client side validations to the dropdown list using javascript?  Hi Good Morning! This is Prasad, I want to perform the client side validation to the dropdown list using javascript. So give me sample.I am
PHP form
PHP form  Hi Sir/Madam, I am developing an attendance form using php, which displays the name and ID of a Employees which are fetched from Db and I... form and update them to respective coloumn... Please any one help mo out please
Form validation
Form validation  Hi Everyone Can someone assist me with a complete code to validate a form. e.g where the user must insert an ID number it should check if the user entered the correct data and within a valid range. This must
other form
other form  Can I write this code in other form: if (quantity>=5) { System.out.println("Congrats!! You get a discount of 5%."); } else { System.out.println("you can avail a discount of 5% when you make a purchase of 5 items
Employee form
Employee form  In employee form emp Id id after any data iserted is incremented for oher data insertion. insert, delete, update buttons when we cleak the select buttoun then the created table data iserted automaticaly
failure to log in
failure to log in  <blockquote> <p>Blockquote</p> </blockquote> <p>&lt;%@page contentType="text/html"%>...; &lt;form name="LoginForm" id="LoginForm" method=post Action="login.jsp"&

Ads