I have a simple application in PHP which uses the following code to hash the password and store it in a db.
<?php
$user_name = "admin";
$password = "1234";
$salt = substr($user_name, 0, 2);
$salt = '$1$' . $salt . '$'; //$salt = $1$ad$
$crypt_password = crypt($password, $salt);
echo $crypt_password;
?>
this code, produces the following password to store in the db: $1$ad$BH3wnQs1wym28vdzP8zyh1
I am trying to make exactly the same code with Java, but as I am new to Java, I have a lot of difficulties. I checked over here http://www.java2s.com/Open-Source/Java-Document/Groupware/LibreSource/md5/MD5Crypt.java.htm#cryptStringString and it seems that it is what I need, but I didn't manage to make it work. Any help would be appreciated. Thank you in advance.