I am developing an android application which has login and register. And I store my database in phpMyAdmin
. I want to store passwords in sha1
. And my application communicate with the database through php
.
My question is that in phpmyadmin what type should be the password column? Varchar or BINARY(20)?
I should convert the password in java or php? Which is easier? Is there any built-in method for that in java or php? Should I use any other encryption?
Should I use this?
private static String encryptPassword(String password)
{
String sha1 = "";
try
{
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(password.getBytes("UTF-8"));
sha1 = byteToHex(crypt.digest());
}
catch(NoSuchAlgorithmException e)
{
e.printStackTrace();
}
catch(UnsupportedEncodingException e)
{
e.printStackTrace();
}
return sha1;
}
private static String byteToHex(final byte[] hash)
{
Formatter formatter = new Formatter();
for (byte b : hash)
{
formatter.format("%02x", b);
}
String result = formatter.toString();
formatter.close();
return result;
}
The formatter which type? Java.util
or java.util.logging
, android.text.format
?