This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes How to check username and pasword.... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to check username and pasword...." Watch "How to check username and pasword...." New topic

How to check username and pasword....

Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
Dear friends,
I want to add security to my application and I'm looking for some sample servlet programs about Login page(username and password) to get some idea...and I'm wondering who can help me... :roll:

Syam Veerakumar
Ranch Hand

Joined: Sep 20, 2001
Posts: 49
Cud u pls let me know what type of code u r looking for, whether its logic to check the user name and password which is available in the database or something else.

A Quitter Never Wins<br />A Winner Never Quits
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
My Frinds,
I mean the servlet code, because I know I need HTML form and I have username and password table in my database as well, just I want to take a look some Servlet program to find out how can I deal with username and password validation....
Many thanks for your following up with me,
rich werth
Ranch Hand

Joined: Sep 21, 2001
Posts: 57
Here is one way to do that
Have ur html page call the servlet that has this code in it
public void checkInfo(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, {
HttpSession session = request.getSession();
try {
userName = request.getParameter("name");
userPass = request.getParameter("pass");
Connection conObject = dbConnect.getCon();
catch(Exception e) {

this is calling a bean that has this code in it
this is a connection bean with connect info in it
public void connect() throws ClassNotFoundException,
Exception {
try {
FileInputStream in = new FileInputStream("c:\\websphere\\appserver\\hosts\\default_host\\testLogon\\config\\");
pm = new Properties();
catch (FileNotFoundException e) {
System.out.println("File not found GO FIND IT! " + e );}
catch (IOException i) { System.out.println("IOException " + i );
} try {
con = DriverManager.getConnection("jdbc racle:thin:@" +(pm.getProperty("oracle.ip"))+":"+(pm.getProperty("oracle.port"))+":"+(pm.getProperty("oracle.sid")),pm.getProperty("oracle.user"),pm.getProperty("oracle.password"));
catch (Exception e) {
error = "Exception: An error occurred while connecting " +
"to database. " + e;
throw new Exception(error);
this is sql for checking user
public ResultSet checkLogon() throws Exception {
ResultSet rs = null;
try {
String queryString = "Select USER_ROLE, USER_ID from TEST_USERS where USER_NAME = '" +userName.trim() + "' and USER_PASS = '" +userPass.trim()+"'";
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
rs = stmt.executeQuery(queryString);
} catch (Exception e) {
error = "An exception occured from data.checkLogon " + e;
throw new Exception(error);
return rs;
Elahe Shafie
Ranch Hand

Joined: Dec 12, 2001
Posts: 291
THank you so much Rich
It is sorta covered in the JavaRanch Style Guide.
subject: How to check username and pasword....
Similar Threads
Form based authentication
Struts Newbie
Authenticating secondary user inside an EJB
logging mechanism
Any Suggestion?