simple code to login user & authenticate it from database mysql

simple code to login user & authenticate it from database mysql

Sir,

I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database.

please tell me the code for it.

Thanks,,

View Answers

July 22, 2011 at 12:46 PM

1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="check.jsp" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Login"></td></tr>
<tr><td></td><td><a href="register.jsp">Register Here</a></td></tr>
</table>
</form>
</html>

2)check.jsp:

<%@page import="java.sql.*"%>
<%
try{
String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
           int count=0;
           while(rs.next()){
           count++;
          }
          if(count>0){
           out.println("welcome "+user);
           }
          else{
           response.sendRedirect("login.jsp");
          }
        }
    catch(Exception e){
    System.out.println(e);
}
%>

July 22, 2011 at 12:47 PM

Please go through the following link:

JSP Login Application









Related Tutorials/Questions & Answers:
simple code to login user & authenticate it from database mysql
simple code to login user & authenticate it from database mysql  Sir, I am creating a login page which contain userid & password. Iwant to authenticate user from mysql database. please tell me the code for it. Thanks
How to view database for user when they login in netbeans and mysql?
How to view database for user when they login in netbeans and mysql?  I create a web page where when user login they have to fill in a form, after... but it come out with all the other user information too. I'm using netbeans and mysql
Advertisements
how to retreive data from database of a particular user after login
how to retreive data from database of a particular user after login  ......please help in display details of particular student after he login ...i want to display the details of only current user who logged
how to retreive data from database of a particular user after login
how to retreive data from database of a particular user after login  ... the user information.. now their is a login and registration page for newuser. after the user has filled the form he should go to the welcome page where he
Error with LogIn with mysql database
Error with LogIn with mysql database  Hi, I have followed steps from your tutorial titled SpringMVClogin with database. I am not using Jetty, as I... is org.hibernate.cfg.beanvalidation.IntegrationException: Error activating Bean Validation integration" My Code
simple code for XML database in JS
simple code for XML database in JS  Sir , i want a code in javascript for XML database to store details (username and password entered by user during registration process (login process)). please send me a code . Thank you
Insert Image into Mysql Database through Simple Java Code
Insert Image into Mysql Database through Simple Java Code... simple java code that how save image into mysql database. Before running...' in database 'mahendra'. Before running this java code you need mysql connector
download code from database
download code from database  how to download files from database
java code for registration and login pages, mysql as a bankend.
java code for registration and login pages, mysql as a bankend.  please send me the java code for registration and login pages and to store the data in mysql
login page using jsp servlrt with mysql database?
login page using jsp servlrt with mysql database?  Description: example:total users are 3.each use have username and password save in mysql database table login. After successfully login user1 see only index page,if user2 login
how to authenticate user using TIVOLI api in java?
how to authenticate user using TIVOLI api in java?  Hi, I want to integrate IBM TIVOLI API to create/authenticate users using java code. Please help....... Thanks in advance
login application
Example Login Authentication using Bean and Servlet In JSP simple code to login user & authenticate it from database mysql Project of a web application...login application  how to create login application ?   Hi
code for user registration page and login page of emails using jsp
code for user registration page and login page of emails using jsp  hiiiiiii please send me the code for user registration page and login page of email using jsp and servlets and also code for database connectivity to oracle
Developing Login Action Class
for login action class and database code for validating the user against database... login. It get the user id and password from the login form and checks the login... is responsible for performing success full login. It get the user id and password from
Spring 3 MVC Login Form Example with Database MySql
Spring 3 MVC Login Form Example with Database MySql  Sir i have checked your project of Spring 3 MVC Login Form Example But Sir Not able to do It with database Mysql. Can you Provide code for login with database. Thanks
Login Authentication in JSP
from the database using MySQL and we are forwarding this servlet data...; For getting values from database we are using MySQL database... Use of Select Box to show the data from database   
Servlet to authenticate user
from the database then client will be entered with authenticate user and password... Servlet to Authenticate User     ...; Statement stmt=null; String url="jdbc:mysql://localhost/jsp?user
Retrieve image from mysql database through jsp
to retrieve image from mysql database through jsp code. First create a database... Retrieve image from mysql database through jsp... Note : In the jsp code given below, image will be retrieved from database
retrieve data from mysql database
retrieve data from mysql database  hi am not familiar in php.....even... selected value on combobox which is to be retrieve the relevant data from mysql database using php.... below my code is that.. <html> <head>
Data retrieve from mysql database
Data retrieve from mysql database  Hi sir, please give some example of jsp code for retrieving mysql database values in multiple dropdown list... code retrieves the employee name in the dropdown. When the user selects any name
Submit comments in database when user clicks on submit button
create a database named "usermaster" in MySql and table named "user... Submit comments in database when user clicks on submit button... to show how to submit comments from a jsp page and insert it to the MySql
Repairing mysql database from command line
Repairing mysql database from command line  Hi, Can anyone tell me the process for repairing mysql database from command line? Thanks
How to retrieve image from mysql database in JSP?
How to retrieve image from mysql database in JSP?  Hi, I need JSP same codes for learning to get image which is stored in MySQL Database. How to retrieve image from mysql database in JSP? Thanks   Hi, You can write
Insert image from user using and save in database
Insert image from user using and save in database  when i am trying to upload a image from user and trying to save into oracle9i database.... Apache Tomcat/6.0.29  We have used MySQl database. 1)page.jsp: <
Fetch user records from a table in database
Fetch user records from a table in database  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from
How to hide HTML code from user? - Security
How to hide HTML code from user?  Hi All, I am trying to provide security to my web application. To achieve this I want to restrict user from... reconstruct your page as well from the code. Look up javascript obfuscation
Spring Security Authorized Access with Customized Login from Database
Spring Security Authorized Access with Customized Login from Database In this section, you will learn about authorized access with customized login from... DEFAULT CHARSET=latin1 You can check user authenticity using customized login from
jsp page to add the user to mysql database
jsp page to add the user to mysql database  adduser.jsp: <...;title>Add User</title> </head> <form name="user" action...;tr> <td>User Name</td> <td><input type
Can anybody help me with this simple MySql code
Can anybody help me with this simple MySql code  select c.countryid, r.bp, r.sp, c.country, t.timee from rate as r, countryloc as c, todaysrate as t where r.countryid=t.countryid and t.countryid=c.country this is waht i gt whn
How to access (MySQL)database from J2ME?
How to access (MySQL)database from J2ME?  I am new to J2ME. I am using NetBeans. Can anyone help me? How to access (MySQL)database from J2ME? ( I search a lot I found that there is need to access database through servlet
jsp code for a drop down box to retrive value from database
jsp code for a drop down box to retrive value from database  my project needs to get the value from database in to the drop down box..... pls give me code for that ..... tan q   1)login.jsp: <html> <script>
data retrival from database throw simple jsp..
data retrival from database throw simple jsp..  We can retrieve the the data from data base simple jsp page: Jsp Page:retrive.jsp <...; Statement stmt = null; String Query="SELECT * FROM STUD"; try
code for insert the value from jsp to access database
code for insert the value from jsp to access database  code for insert the value from jsp to access database
How to create simple HTML Login Page?
script to validate the user against database. Try Login form: try the Simple...Simple HTML Login Page- Create a Simple HTML Login page and validate... of making a simple login form and validating it using JavaScript. JavaScript
How to create simple HTML Login Page?
by server side script to validate the user against database. Try Login form... Form JSP Login Form with MySQL Database Connection and back end...Simple HTML Login Page- Create a Simple HTML Login page and validate
Dropdown code to retrieve result from oracle database
that will retrieve values from the database into dropdown. As the user choose any option...Dropdown code to retrieve result from oracle database  Hi Friends, I... retrieve the result from Oracle database.We have procedures created already.Just
JSP Login Form with MySQL Database Connection and back end validation
Here we have created a simple login form using MySQL Database Connection... We will create a simple login logout example using JSP. When a user inputs... Following video will help you to create JSP Login form backed with MySQL database
How to insert image in sql database from user using servlet
How to insert image in sql database from user using servlet  pls tell me accept image from user and insert image in sql server 2005 database using servlet and jsp
retrieve data from mysql database and store it in a variable ?
retrieve data from mysql database and store it in a variable ?  sir... that retrieve the integer values from the database and stored in the integer... which is stored in mysql. so to apply some arithmetic operation on it we have
simple code to write an read and write the login detail to a xml file using javascript ( username and password )
simple code to write an read and write the login detail to a xml file using javascript ( username and password )  pls can nyone give me a code to write and read the login details (username and password )into a xml file using
MySql Databse query to fetch results from database
MySql Databse query to fetch results from database  Hi. I have a field in database named stages. its datatype is varchar(60). It contains values chennai,trichy,kanchipuram for a single record. I have to retrieve these data from
problem in selecting second arraylist from mysql database
problem in selecting second arraylist from mysql database  Hi... in mysql database. In the below program , i have hard-coded that second list, but i want second list to be dynamic from database. Please, help me out. Thank
Video Tutorial: How to access MySQL database from JSP?
How to access MySQL database from JSP? In this tutorial,I will teach you how to access data from JSP page. We are using MySQL database and we have a table... to access MySQL database from JSP?": So, we have pasted it here
Spring Security customized login from database
Spring Security customized login from database In this section, you will learn... page but the login is checked from the database table. We have added spring... and login credential from the database table.ADS_TO_REPLACE_5 <?xml version
how to retrive the particular data from database in php with mysql?
how to retrive the particular data from database in php with mysql?  ..._db("samp", $con); $Name=$_POST['unames']; $data=mysql_query("SELECT * FROM tbl... in advance  http://www.roseindia.net/tutorial/php/phpdatabase/PHP-MySQL-Login
code for selected checkbox columns data from database
code for selected checkbox columns data from database  in my page iam getting all column names of a particular table with checkboxes. when iam select... is the jsp code for this thanks in advance kalyani
How to prevent from navigating to ck buttonnext page when user reaches login page using back button
How to prevent from navigating to ck buttonnext page when user reaches login... goback to user login page using back button and agin click browser forward button... document opens..But i dont want it to happen.Instead,it should again ask for login
Data needs to be gathered in XML file from the database (MySql) using JSP
Data needs to be gathered in XML file from the database (MySql) using JSP ... data regarding particular id from the database table. Data needs to be gathered in XML file from the database (MySql) using appropriate JSP/Java Bean functions
simple web appllication to insert, update or display from database - JSP-Servlet
simple web appllication to insert, update or display from database  ... in which we can insert, update or delete data from database. i can also display database content on jsp page. please send complete code. thank you mani saurabh
User LogIn According to Role
User LogIn According to Role  User login According to role but output will be always displayed in a single page.. but content will change according role

Ads