File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Servlet Authentication" Watch "Servlet Authentication" New topic
Author

Servlet Authentication

ankita balaji
Greenhorn

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());
ps.setString(1,_naam);
ps.setString(2,_wachtwoord);
ResultSet rs = ps.executeQuery();
if (rs.next() )
{
Gebruiker gebruiker = new Gebruiker(rs);
rs.close();
ps.close();
con.close();
mopoLogger.debug("gebruiker gevonden " + gebruiker.getNaam());
return gebruiker;
}
else {
ps.close();
con.close();
mopoLogger.debug("geen gebruiker gevonden");
return null;
}

} // end findGebruiker

} // end GebruikerDao
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Servlet Authentication