• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to check username and pasword....

 
Ranch Hand
Posts: 291
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THank you so much Rich
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic