Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created a html login page in which user enter the name and password and I want to compare the name and password to the database for existance if user exist the login else error.for database use mysql.

What I have tried:

#servlet page
Try
{
Class.forName("sun.jdbc.odbc.jdbcodbcdriver");
System.out.println("driver loaded");
Connection.con=DriverManager("jdbc:odbc:five");
System.out.println(database loaded);
PreparedStatement ps=con.preparedStatement("select name from table");
Results rs=ps.executQuery();
String s=JTextField.getText();
String s1= rs.getString("name");
If(s.equals(s1)){
Matched

}
else{
Invalid user;
}
}
#html page

Name
Posted
Updated 1-Feb-18 22:19pm
v3

1 solution

What does "not work" mean? Please remember, we cannot see your screen or guess what you have done. You need to show your code and explain exactly what is happening.

You should start by reading Secure Password Authentication Explained Simply[^] to ensure you are storing your passwords securely. Also check bobby-tables.com: A guide to preventing SQL injection[^] to see that you are protecting the integrity of your database.
 
Share this answer
 
Comments
Pmourya 2-Feb-18 4:20am    
Ok,Pls recheck
Richard MacCutchan 2-Feb-18 4:42am    
Your SELECT query is returning all the names in the database, so if the first one does not match the textbox you reject it. You should query for only the name that the user enters. See MySQL :: MySQL 5.7 Reference Manual :: 13.2.9 SELECT Syntax[^] for a full explanation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900