This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to check username and pasword....  RSS feed

 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Thanks,
Elahe
 
Syam Veerakumar
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Syam.
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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,
ELahe
 
rich werth
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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, java.io.IOException {
HttpSession session = request.getSession();
try {
userName = request.getParameter("name");
db.setUserName(userName);
userPass = request.getParameter("pass");
db.setUserPass(userPass);
dbConnect.connect();
Connection conObject = dbConnect.getCon();
db.setCon(conObject);
rs=db.checkLogon();
}
catch(Exception e) {
e.printStackTrace();
}

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,
SQLException,
Exception {
try {
FileInputStream in = new FileInputStream("c:\\websphere\\appserver\\hosts\\default_host\\testLogon\\config\\test.properties");
pm = new Properties();
pm.load(in);
}
catch (FileNotFoundException e) {
System.out.println("File not found GO FIND IT! " + e );}
catch (IOException i) { System.out.println("IOException " + i );
} try {
Class.forName(pm.getProperty("oracle.driver")).newInstance();
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;
}
cheers
 
Elahe Shafie
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
THank you so much Rich
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!