Login authentication

Login authentication

i want d code for login authentication from mysql database on the same pc using swings

View Answers

January 20, 2011 at 3:24 PM

Hi Friend,

Try the following code:

1)LoginDemo.java:

import javax.swing.*;
import java.sql.*;
import java.awt.*;
import java.awt.event.*;

class LoginDemo extends JFrame{
 JButton SUBMIT;
 JLabel label1,label2;
 final JTextField  text1,text2;
  LoginDemo(){
    setTitle("Login Form");
    setLayout(null);
    label1 = new JLabel();
    label1.setText("Username:");
    text1 = new JTextField(15);

    label2 = new JLabel();
    label2.setText("Password:");
    text2 = new JPasswordField(15);

    SUBMIT=new JButton("SUBMIT");
    label1.setBounds(350,100,100,20);
    text1.setBounds(450,100,200,20);
    label2.setBounds(350,130,100,20);
    text2.setBounds(450,130,200,20);
    SUBMIT.setBounds(450,160,100,20);
   add(label1);
   add(text1);
   add(label2);
   add(text2);
   add(SUBMIT);

   setVisible(true);
   setSize(1024,768);

 SUBMIT.addActionListener(new ActionListener(){
   public void actionPerformed(ActionEvent ae){
    String value1=text1.getText();
    String value2=text2.getText();
    try{
 Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+value1+"' and password='"+value2+"'");
           int count=0;
           while(rs.next()){
               count++;
           }
          if(value1.equals("") && value2.equals("")) {
          JOptionPane.showMessageDialog(null,"Enter login name or password","Error",JOptionPane.ERROR_MESSAGE);
          }
          else if(count>0){
          NextPage page=new NextPage(value1);
          page.setVisible(true);
          }
          else{
          text1.setText("");
          text2.setText("");
          JOptionPane.showMessageDialog(null,"Invalid Login name or password","Error",JOptionPane.ERROR_MESSAGE);
          }
    }
    catch(Exception e){}
}
 });
  }
  public static void main(String arg[]){
  new LoginDemo();
}
}

2)NextPage.java:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

class NextPage extends JFrame
{
  NextPage(String st)
   {
      setLayout(null);
     setDefaultCloseOperation(javax.swing. WindowConstants.DISPOSE_ON_CLOSE);
     setTitle("Welcome");
     JLabel lab=new JLabel("Welcome  "+st);
     lab.setBounds(10,10,500,20);

     add(lab);
     setSize(1024, 768);
      }
 }

Thanks









Related Tutorials/Questions & Answers:
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Login authentication
Login authentication  i want d code for login authentication from mysql database on the same pc using swings
Advertisements
login authentication - Java Beginners
login authentication  i 've designed the jsp page for login. now i need to connect it with the bean and do authentication for the login for the "register" table in mysql. can anybody help me with the code immediately
login authentication in jsp and servlet
login authentication in jsp and servlet  Hi, I am beginner in web... to make login authentication in jsp and servlet? Thanks   Hi, I to make login authentication in jsp and servlet you have to write code for database
Struts Login Authentication
Struts Login Authentication  Hi Sir, Am doing a project in a struts 1.2,i want login authentication code fro that, only authenticated user can login into application,i am using back end as Mysql.so send me code as soon
ModuleNotFoundError: No module named 'login_authentication'
ModuleNotFoundError: No module named 'login_authentication'  Hi...: No module named 'login_authentication' How to remove the ModuleNotFoundError: No module named 'login_authentication' error? Thanks   Hi
JDbc Login Authentication
JDbc Login Authentication  Pease Please.. Send Me one Login Authentication Using ComboBox.From Servlet and jsp with sessions I am new to sessions..." value="Login"><input type="reset" Value="Cancel" ></input><
login authentication - Development process
login authentication  hi.. how to validate username and password for both admin and user using java script which is retrive from backend
login authentication - Java Beginners
login authentication  i 've problem in authenticating users thru jsp...()){ System.out.println("login success...("Login failed"); //username
Login authentication & mysql - Java Beginners
Login authentication & mysql  Hi , Could you guide or provide sample coding for the following scenerio. I need to code authentication for user login I need to create a user account which is the user can register
Login Authentication using existing Active Directory.
Login Authentication using existing Active Directory.  I need jsp code for login authentication of username and password using already existing Active Directory. Here no need to create active directory.The JSP code should
Login Authentication and session in JSP - JSP-Servlet
Login Authentication and session in JSP  Hi, I am creating an small application in JSP,in which i need to check user authentication and session on each JSP page.Also how do i make logout page. Can you help me
login and registration form using servlet and authentication through mysql
login and registration form using servlet and authentication through mysql  i made a simple login and rgistration form using servlet and authentication through mysql and whenevr i run it on tomcat a blank page is displayed plz
Login Authentication using Bean and Servlet In JSP
Login Authentication using Bean and Servlet In JSP... developed a web application of login authentication using Bean  in JSP. Five...;/body> <html> Output: ADS_TO_REPLACE_6 Login Authentication form
redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.
redirecting a login authenticated form to a form to be displayed on the same page from where the login authentication has taken place.  I am successfully able to create a session on successful login, but I want to display
login
login  How to create login page in jsp
login
login  How to create login page in jsp
login
login  login page display an error showing failure to login even when the correct information is entered
login
login  how to login admin and user with the same fields(name & password) in single login page while the table for admin and user is seprate in database(mysql) please provide me solution
login
login  i want to now how i can write code for form login incolude user and password in Jcreator 4.50   Hello Friend, Visit HereADS_TO_REPLACE_1 Thanks
login
java.awt.event.*; class Login { JButton SUBMIT; JLabel label1,label2; final JTextField text1,text2; Login() { final JFrame f=new JFrame("Login Form...(); ResultSet rs=st.executeQuery("select * from login where username='"+value1
login
login  how to create login page in jsp   Here is a jsp code that creates the login page and check whether the user is valid or not. 1...;tr><td></td><td><input type="submit" value="Login">
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
login
login  i am doing the project by using netbeens.. it is easy to use the java swing for design i can drag and drop the buttons and labels etc.. now i want the code for login.. i created design it contains the field of user name
Authentication
interface for login */ } public void addLoginListener(LoginListener login) { this.login = login; } public void fireLoginEvent(LoginEvent loginE
login application
login application  how to create login application ?   Hi, Please check the following tutorials: Video tutorial - JSP Login Logout Example Login Authentication using Bean and Servlet In JSP simple code to login user
Login Program
Login Program  Login program in struts to set username & password in session. and this session is available in all screens for authentication...   Hi, Please read it at:ADS_TO_REPLACE_2 Login/Logout With Session
Login Form
of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so...Login Form  I have 8 jsp pages.Each of them has three columns:Left
Login Form
of +,on clicking which a login form appears. Only the middle column is different for each of the page. How to write a code for login authentication so...Login Form  I have 8 jsp pages.Each of them has three columns:Left
Login Screen of Application
Login Screen of Application       Login Screen our web application allows the user... in the database and once the authentication is successful user is allowed
login page
login page  code for login page
Authentication - JavaMail
Authentication program in Java  How to write a program in Java for user authentication
Authentication in Servlets
Authentication in Servlets  What are different Authentication options available in Servlets
Login page
Login page  how to create Login page in java
login page
login page  How to login as different user in php
login-logout
login-logout  how to do login and logout using session in php
LOGIN ERROR
LOGIN ERROR  ERROR SCRIPT: LOGIN FAILED", $_SESSION['login fail']='0',}?> Ty Team
Login Page
Login Page  Can anyone tell me the steps to create a login page in myeclipse 7.0 and validating it with login database in db2 9.7 ??? Please tell me
Login Authentication in JSP
LOGIN PAGE
LOGIN PAGE  A java program with "login" as title,menus added, and a text field asking for firstname, lastname, and displaying current date and time
Can Login on Fedora, cannot on Windows- JSP/Servlet for login
; Please visit the following link: JSP Login Authentication...Can Login on Fedora, cannot on Windows- JSP/Servlet for login  I am using JSP and Servlet to perform login. When I host the website and test it works
JSF Simple Login Application
:view> <html> <head><title>JSF Simple Login Example<...;td><h:outputText value="Enter Login ID: " /></td> <... for the resultforfail.jsp file: Login Failed! Here is the code
Login modification
Login modification  How can I invalidate a user once he goes back to login page without signing out,I have already tried using session but it doesn't work please help
Authentication - Struts
Authentication  Hello everybody, How to provide high level authentication in struts application
login box
login box  class file for password and conform password and how it connected to database
login page
login page  pls say how to create a login page in jsp and mysql using netbaens   Hi Friend, Please visit the following links:ADS_TO_REPLACE_1 http://roseindia.net/jsf/netbeans/index.shtml http://roseindia.net/jsp
login data
login data   Hiiii Sir I am doing banking project on Asp.net i have... the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance
login data
login data  Hiiii Sir I am doing banking project on Asp.net i have... the data after login i want to show particular data for particular user means if i login i wanna see only myn data how shud i do thanxx in advance

Ads