1

This is how I store data on firebase.But can anyone suggest, how to encrypt password and save it?

   save.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String user,pass;
            user =name.getText().toString();
            pass=password.getText().toString();

            Firebase usersRef = Ref.child("user");
          //  usersRef.child("username").setValue(user);
          //  usersRef.child("password").setValue(pass);

            Map<String,String> mUser = new HashMap<String, String>();
            mUser.put("username",user);
            mUser.put("password",pass);
            usersRef.push().setValue(mUser);

        }
    });
Uroš Podkrižnik
  • 8,607
  • 5
  • 21
  • 31
  • Are you want to Encrypt Password String ? – Rajan Bhavsar Aug 04 '15 at 04:48
  • yes. actually i want first to signup user with details like country,username,email,password,then using email and password ,i want to log to home page.then next process is create chat app – Dhanraj Naik Aug 04 '15 at 04:55
  • If you want to encrypt the Password then i suggest to go with this.http://stackoverflow.com/questions/339004/java-encrypt-decrypt-user-name-and-password-from-a-configuration-file – Rajan Bhavsar Aug 04 '15 at 04:56

2 Answers2

5

You can use any encryption method to encrypt your password but one of the best practice for encrypting password is to use MessageDigest.

You can use below method to convert your password with MD5 and encrypt it.

public static String convertPassMd5(String pass) {
        String password = null;
        MessageDigest mdEnc;
        try {
            mdEnc = MessageDigest.getInstance("MD5");
            mdEnc.update(pass.getBytes(), 0, pass.length());
            pass = new BigInteger(1, mdEnc.digest()).toString(16);
            while (pass.length() < 32) {
                pass = "0" + pass;
            }
            password = pass;
        } catch (NoSuchAlgorithmException e1) {
            e1.printStackTrace();
        }
        return password;
    }
Paresh Mayani
  • 127,700
  • 71
  • 241
  • 295
Dhrumil Shah - dhuma1981
  • 15,166
  • 6
  • 31
  • 39
0

use message Digest for encryption of password.