0

i want to store encrypted password in my mysql database.

i have insert the password like ari means have to save the password like B-dd2c1cd0250859d32754fdd85ffc0531.

But i have to insert the data(ari) means the ari is displayed on my database.how can i encrupt the password and save the password like above format.

For eg: ari is save in database like these format B-dd2c1cd0250859d32754fdd85ffc0531.how can i do.please help me.

i have wrote the code:

public class Insert {

   public String insertData(String userName,String userPassword){

   try{

   Class.forName("com.mysql.jdbc.Driver");
  Connection con =  DriverManager.getConnection("jdbc:mysql://server:3306/android","XXXX","XXX");
   PreparedStatement statement =  con.prepareStatement("INSERT INTO xcart_customers(login,password) VALUES ('"+userName+"','"+userPassword+"');");
       int result = statement.executeUpdate();
       }

          catch(Exception exc){
            System.out.println(exc.getMessage());
          }

          return "Insertion successfull!!";
        }}

This is my Demo.java class:

public class Demo {
public static void main(String[] args){
    Insert obj = new Insert();
    System.out.println(obj.insertData("krishna", "ari"));
   }
  }
user1897014
  • 143
  • 4
  • 14

3 Answers3

0

You need to look at password hashing and salting. Have a look at this post.

EDIT:

Remember Hashing is One way! so you can't expect to convert the Hashed value back to the clear text (in this case ari). What you can do is when login works you can check user entered value is equal or not to the database value.

shazin
  • 21,379
  • 3
  • 54
  • 71
0

Without knowing which scheme was used to encrypt the existing data, there's no way to tell how you can achieve compatibility. If you can start all over again, bcrypt is the way to go.

gustafc
  • 28,465
  • 7
  • 73
  • 99
0

Looking at the sql query INSERT INTO xcart_customers(login,password) I guess you are trying to encrypt passwords for X-CART.

X-CART uses Blowfish key-based encryption. You can find your key from config.php -file.

Here's a already answered question about encrypting blowfish with a key in java which might help figuring out how encrypt it

Encryption with BlowFish in Java

Community
  • 1
  • 1
  • Hi.,this is my updated code like:http://pastie.org/5555969 here i got the following error :Cannot find any provider supporting password whats wrong in my code.please tell me – user1897014 Dec 20 '12 at 06:48