You want to convert char[] to String . When you call tb_pwd.getPassword (), char [] (an array of characters) is returned. If you want to compare this password, you must convert it to String, and for this you can use this method:
String final_pass = ""; for(char x : passwordAsChar[]) { final_pass += x; }
As for comparing passwords in databases, you should never store them in text, unencrypted form. You can save the MD5 string in your database and convert your user-entered password to String, and then include the following method in it. Then compare the returned row with one of the database. If they match, the user entered the correct password.
Example:
char[] pass = tb_pwd.getPassword(); String final_pass = ""; for (char x : pass) { final_pass += x; } String md5_encrypted_pass_userInput = encrypt(final_pass); if (md5_encrypted_pass.equals(pass1)) {
Usage method for encrypting strings for MD5:
public static final String encrypt(String md5) { try { java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5"); byte[] array = md.digest(md5.getBytes()); StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3)); } return sb.toString(); } catch (java.security.NoSuchAlgorithmException e) {} return null; }
source share