Forums Register Login

How to check username and pasword....

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
THank you so much Rich
Something about .... going for a swim. With this tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1565 times.
Similar Threads
Form based authentication
Struts Newbie
Any Suggestion?
Authenticating secondary user inside an EJB
logging mechanism
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 02:13:36.