This works just fine. But I feel in real time projects, since the number of
users browsing the site is likely to be higher, it would be better to use
the connection pooling in the init() method, rather than creating a
connection object in the doPost () method.
-----Original Message-----
From: Don Junio Edillor [SMTP:[EMAIL PROTECTED]]
Sent: Tuesday, March 28, 2000 3:34 PM
To: [EMAIL PROTECTED]
Subject: Re: password/username
this is just another simple sample of a password confirmation
servlet..
there is no encryption included for simplicity..
this the code:
//code begins
import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Verify extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse
res)
throws ServletException,
IOException {
Connection con = null;
Statement stmt = null;
ResultSet rs = null;
int verified = 0;
res.setContentType("text/html");
PrintWriter out = res.getWriter();
String userName = req.getParameter("txtUserName");
String password = req.getParameter("txtPassword");
try {
// Initialize driver...
Class.forName(<database driver>);
// Connect...
con = DriverManager.getConnection(<database connection
with username
and password>);
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT USERNAME, PASSWORD FROM
JOJOUSERS"
+ " WHERE USERNAME = '" +
userName +
"'");
// HTML Header...
out.println("<HTML><HEAD><TITLE>Verification Result"
+ "</TITLE></HEAD>");
out.println("<BODY>");
while(rs.next()) {
if(rs.getString("password").trim().equals(password.trim())) {
verified = 1;
}
}
if(verified == 1) {
out.println("User verified: Access Granted");
} else {
out.println("Access Denied...<BR>User not found or "
+ "Incorrect Password!");
}
// HTML footer...
out.println("</BODY></HTML>");
}
catch(ClassNotFoundException e) {
out.println("Couldn't load database driver: " +
e.getMessage());
}
catch(SQLException e) {
out.println("SQLException caught: " + e.getMessage());
}
finally {
try {
if (con != null) con.close();
}
catch (SQLException ignored) { }
}
}
public String getServletInfo() {
return "Login verification sample... ";
}
}
// end of the code
>From: Abhishek sharan
<[EMAIL PROTECTED]>
>Reply-To: "A mailing list for discussion about Sun Microsystem's
Java
> Servlet API Technology." <[EMAIL PROTECTED]>
>To: [EMAIL PROTECTED]
>Subject: Re: password/username
>Date: Tue, 28 Mar 2000 12:45:08 +0530
>
>Tim Brummer wrote:
>
> > I'm looking for a basic servlet that authenticates a users
password and
> > user name from an access database.
> > Thanks in advance
> >
>
>Hi Tim ,
> i've inculded the source for the servlet that does this
> hope it helps
>thanks
>Abhishek Sharan
>MTS,InterSolutions
>Noida
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in
the body
of the message "signoff SERVLET-INTEREST".
Archives:
http://archives.java.sun.com/archives/servlet-interest.html
Resources:
http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html