|
private static void insertRecord() throws SQLException
{
Connection con = null;
Statement statement = null;
try
{
PreparedStatement PS = Connectionstring().prepareStatement("INSERT INTO LoginDetails(Username,Password) VALUES (?,?)");
String User = tf_Uname.getText();
String _Pass = new String(tf_pass.getPassword());
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA-256");
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
md.update(_Pass.getBytes());
byte byteData[] = md.digest();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < byteData.length; i++) {
sb.append(Integer.toString((byteData[i] & 0xff) + 0x100, 16).substring(1));
}
System.out.println("Hex format : " + sb.toString());
StringBuffer hexString = new StringBuffer();
for (int i=0;i<byteData.length;i++)
{
String hex=Integer.toHexString(0xff & byteData[i]);
if(hex.length()==1) hexString.append('0');
hexString.append(hex);
}
System.out.println("Hex format : " + hexString.toString());
PS.setString(1, User);
PS.setString(2, _Pass);
PS.executeUpdate();
JOptionPane.showMessageDialog(null,"Your Data has been Inserted","Data Inserted",JOptionPane.INFORMATION_MESSAGE);
}
catch (SQLException e)
{
System.out.println(e.getMessage());
}
finally
{
if (statement != null)
{
statement.close();
JOptionPane.showMessageDialog(null,"Statement is closed","Statement",JOptionPane.INFORMATION_MESSAGE);
}
if (con != null)
{
con.close();
JOptionPane.showMessageDialog(null,"Connection is closed!","Connection",JOptionPane.INFORMATION_MESSAGE );
}
}
}
I'm getting the right output but could not able to save the hash password into the database it's being stored as a Text.
|
|
|
|
|
Hello chdboy please check this line
PS.setString(1, User);
PS.setString(2, _Pass);
PS.executeUpdate();
you have provided normal text to user and password field
While you need to provide hex code in this line no 1 and 2
|
|
|
|
|
Thanks a lot ...now let's see if there is a problem in getting hex code back to the string when user enter details .![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
You shouldn't need to, that means anyone else can, and your system is not secure. Passwords should use one-way hashes so they can never be converted back to the original string. See Secure Password Authentication Explained Simply[^].
Use the best guess
|
|
|
|
|
I am new to Java and Web Development. I need to build a Java server App, which has to interact with MySQL DB stored procedures and fetch rows and return to client.
1. Client can be from Http request from web browser
2. An Android app
3. Desktop app
4. and others
Now my question is; should the server App be
1.JSP
2.Servlet
3.WebService
Load balancing should be done for Server App, and server App is going to be 3-tire
Please advice the Pro/Cons in each case.
|
|
|
|
|
This question is far too broad for a technical forum such as this. You need to do your own research and study before deciding which technologies will be best to address your problem.
Use the best guess
|
|
|
|
|
I want to validate Username and Password matching from my sql Database,but it didn't work.Even if the text fields are blank it does not give any error.
private static void selectfromdb() throws SQLException
{
Statement stmt = Connectionstring().createStatement();
ResultSet rs = stmt.executeQuery("SELECT Username,Password FROM LoginDetails where Username='"+tf_Fname+"' AND Password ='"+tf_Lname+"'");
while (rs.next())
{
String x = tf_Fname.getText();
String pass = new String(tf_Lname.getPassword());
if (x.equals(rs.getString("Username")))
{
if (pass.equals(rs.getString("Password")))
{
JOptionPane.showMessageDialog(null,"Login Successful! ","Success",JOptionPane.WARNING_MESSAGE);
}
else
{
JOptionPane.showMessageDialog(null,"Login UNSuccessful! ","UNSuccessful",JOptionPane.WARNING_MESSAGE);
}
}
}
}
|
|
|
|
|
Try this
private static void selectfromdb() throws SQLException
{
Statement stmt = Connectionstring().createStatement();
ResultSet rs = stmt.executeQuery("SELECT Username,Password FROM LoginDetails where Username='"+tf_Fname+"' AND Password ='"+tf_Lname+"'");
rs.last();
int rowcount = rs.getRow();
if(rowcount ==0){
JOptionPane.showMessageDialog(null,"Login UNSuccessful! ","UNSuccessful",JOptionPane.WARNING_MESSAGE);
}
else{
JOptionPane.showMessageDialog(null,"Login Successful! ","Success",JOptionPane.WARNING_MESSAGE);
}
}
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
Blue_Boy wrote:
ResultSet rs = stmt.executeQuery("SELECT Username,Password FROM LoginDetails where Username='"+tf_Fname+"' AND Password ='"+tf_Lname+"'");
It is really bad form to give sample code that can lead to SQL injection[^].
Use the best guess
|
|
|
|
|
I didn't gave example to use query which is able to inject, the user used by him/herself, i just gave solution how to manage login case.
I Love T-SQL
"VB.NET is developed with C#.NET"
If my post helps you kindly save my time by voting my post.
|
|
|
|
|
In both the cases even if it's right password it shows "Login UNSuccessful"
|
|
|
|
|
Use your debugger to step through the code and see what values your variables contain at each stage.
Use the best guess
|
|
|
|
|
The row count is 0 when I debug it....but I'm using the same username and password what's in the database,why is it not accepting it?
|
|
|
|
|
chdboy wrote: The row count is 0 when I debug it....but I'm using the same username and password what's in the database,why is it not accepting it? I have no idea since I have no access to your system. You need to investigate further to discover what is happening.
Use the best guess
|
|
|
|
|
Now I have changed the code
PreparedStatement preparedStatement = Connectionstring().prepareStatement(
"Select Username from dbo.LoginDetails where Username = ? and Password =?");
String User = tf_Fname.getText();
String _Pass = new String(tf_Lname.getPassword());
preparedStatement.setString(1, User);
preparedStatement.setString(2, _Pass);
ResultSet resultSet = preparedStatement.executeQuery();
while (resultSet.next())
{
System.out.println("Username is "+ resultSet.getString(1)+"Password is "+resultSet.getString(2));
}
But now it's picking up the right Username from the table ,if I don't use
+"Password is "+resultSet.getString(2) in the Print line,and if I use that I get an error
com.microsoft.sqlserver.jdbc.SQLServerException: The index 2 is out of range.
|
|
|
|
|
I guess that you need to look more closely at the contents of your ResultSet and its individual property items. Check with your debugger and also the documentation for the classes that you are working with.
Use the best guess
|
|
|
|
|
I think I got what is wrong with it.....I'm missing Select Username,Password ...hehe thanks
|
|
|
|
|
So the code is telling you the values are not equal.
Figure out what the values are and you will see the difference. Either a debugger or a print them out.
But as a guess there is a case difference. The query doesn't care but the comparison does.
|
|
|
|
|
com.microsoft.sqlserver.jdbc.SQLServerException: The result set has no current row.
But when I see it in the Database there are plenty of rows.
I don't understand why it is not picking up the rows ?
|
|
|
|
|
How would one mutate an object that is final? By referencing the object and then doing a mutate() operation on it? e.g.:
final Object o = new Object();
o.mutate();
I don't understand. If it was declared final, then how come you are allowed to mutate it (or is that not true)?
How would one make the Object immutable then? Meaning: not mutable in any way, not even by reference.
How do I make sure a reference cannot modify the object it refers to? So that MyObject o = new Object(); o.modify(); is not possible?
I also read on Wikipedia the following example:
final Position pos = new Position();
members:
pos.x, pos.y, pos.z are mutable still, unless they are declared final.
So if I am understanding this correctly, in order to make an object/class completely immutable, everything in it including its reference has to be declared final? e.g.:
final Position pos = new Position();
class Position {
final int x;
final int y;
final int z;
public Position(){
x=1;
y=2;
z=3;
}
final void doA(){}
final void doB(){}
}
|
|
|
|
|
|
Referring to that article, Listing 1: Q.: "Because Date is mutable, the scheduleTask method must be careful to defensively copy the date parameter (perhaps through clone()) into its internal data structure. Otherwise, task1 and task2 might both execute tomorrow, which is not what was desired. Worse, the internal data structure used by the task scheduler could become corrupt."
A few questions on this:
1) What is 'copying defensively'?
2) What do they mean by 'internal data structure'?
3) How could task1 and task2 execute tomorrow if the code is to be executed today? Then how can new Date() be tomorrow? I don't understand.
4) How would the internal data structure become 'corrupt'? What is 'corrupt' in this context? Containing inconsistent values?
|
|
|
|
|
These questions should be addressed to the writer of that white paper.
Use the best guess
|
|
|
|
|
Hi,
Iam looking for complete example using Spring to get connection pool object(datasource) which is created in websphere server.
I have tried in many ways but no luck facing with different kind of errors.
Thanks in advance for your time.
|
|
|
|
|
Greetings all.
I have a program calculation ip address like this.
public static void main(String[]args){
int host=450;
String sMask="255.255.254.0";
String[] octet;
String IpAddress="192.168.100.0";
octet = IpAddress.split("\\.");
int oct1=Integer.parseInt(octet[0]);
int oct2=Integer.parseInt(octet[1]);
int oct3=Integer.parseInt(octet[2]);
int oct4=Integer.parseInt(octet[3]);
int i;
System.out.println("Ip Address \t \tSubnet Mask");
for(i=oct4;i<host;i++){
System.out.println(oct1+"."+oct2+"."+oct3+"."+i+"\t \t"+sMask);
}
}
print out from this program
Ip Address Subnet Mask
192.168.100.0 255.255.254
192.168.100.1 255.255.254
192.168.100.2 255.255.254
192.168.100.3 255.255.254
until...
192.168.100.449 255.255.254
I want this program,if ip address octet 4 value "192.168.100.255",then continuing this program,like this.
next >
192.168.101.0 255.255.254
192.168.101.1 255.255.254
192.168.101.2 255.255.254
until ...
192.168.101.193 and Finish.
What the lack from my program?
|
|
|
|