File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Servlet Authentication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Authentication" Watch "Servlet Authentication" New topic

Servlet Authentication

ankita balaji

Joined: Aug 19, 2004
Posts: 11
Hai Everybody,
Good evening.Iam new to servlet world and i require a small help from U.Can anyone give me the code for the user name and password authentication using servlets with jdbc as connectivity plz
Gert Cuppens
Ranch Hand

Joined: Jul 13, 2003
Posts: 87
Here's an example in which I look up the user & password combination in the database. If I find the combination, I allow the user to log in to web application.

package org.gertcuppens.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.gertcuppens.general.Gebruiker;

/* import org.apache.log4j */
import org.apache.log4j.Logger;

public class GebruikerDao extends GeneralDao {

* Zoekt de gebruiker op aan de hand van de opgegeven naam en wachtwoord
* @return Gebruiker
* @param _naam
* @param _wachtwoord
public Gebruiker findGebruiker(String _naam, String _wachtwoord)
throws SQLException
Logger mopoLogger = Logger.getLogger("mopo.log");
mopoLogger.debug("start findGebruiker" );
StringBuffer zoekString = new StringBuffer();
zoekString.append ("select * from gebruiker ");
zoekString.append("where naam=? and wachtwoord=? ");
Connection con = getConnection();
PreparedStatement ps = con.prepareStatement(zoekString.toString());
ResultSet rs = ps.executeQuery();
if ( )
Gebruiker gebruiker = new Gebruiker(rs);
mopoLogger.debug("gebruiker gevonden " + gebruiker.getNaam());
return gebruiker;
else {
mopoLogger.debug("geen gebruiker gevonden");
return null;

} // end findGebruiker

} // end GebruikerDao
I agree. Here's the link:
subject: Servlet Authentication
It's not a secret anymore!