Two Laptop Bag*
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to check username and pasword...." Watch "How to check username and pasword...." New topic
Author

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:
Thanks,
Elahe


Thanks,
Elahe
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.
Syam.


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,
ELahe
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, 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

Joined: Dec 12, 2001
Posts: 291
THank you so much Rich
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to check username and pasword....
 
Similar Threads
Form based authentication
Struts Newbie
Authenticating secondary user inside an EJB
logging mechanism
Any Suggestion?