A small tool to generate password for platform server

Related to topic Adding Users during Plattform Server Startup, I wrote a small tool to generate password for your user.
You can see in that topic you can config your user informations in xml file: username, first name, last name, email,… But how about password? It is encrypted. You can reuse password and salt in that xml file (password is admin), or you can use my tool to generate any password you want.

generatepassword.zip (352.5 KB)

How to use it?

  • Download zip file above and extract it.
  • Go to extracted folder and run
java -cp ".:./shiro-core-1.4.0.jar" GeneratePassword passwort cf41c880e9b55316c3b8ccb0e8aad01f

In this case passwort is your password and cf41c880e9b55316c3b8ccb0e8aad01f is your salt.
You will receive an output like that:

plainTextPassword: passwort
salt: cf41c880e9b55316c3b8ccb0e8aad01f
password: ddff2638b2583e6a937217b358b524f30b0b5e5be6122122cc199f2a804fe4db66b6ccb646db469e75c8f63ce54e8695284708473a168c76bb8c59764ccd20d7

Now you got encrypted password. Put encrypted password and salt to your xml file. Your user can login with password passwort.

FYI, here is my code:

import org.apache.shiro.codec.Hex;
import org.apache.shiro.crypto.hash.Sha512Hash;
import org.apache.shiro.util.ByteSource;
import org.apache.shiro.util.SimpleByteSource;

public class GeneratePassword {
    public static void main(String[] args){
        String plainTextPassword = args[0];
        String salt = args[1];
        final ByteSource saltByteSource = new SimpleByteSource(Hex.decode(salt));
        String password = new Sha512Hash(plainTextPassword, saltByteSource, 200000).toHex();
        System.out.println("plainTextPassword: " + plainTextPassword);
        System.out.println("salt: " + salt);
        System.out.println("password: " + password);
    }
}

We have been discussing creating stuff like this but we had no requirement yet. There is one more thing that is missing in your app and it is the hash iterations that are configurable:

mgm.services.core.user.credentials-hash-iterations=200000

And in your application has it hard coded. @ansgar-solar-lake do you think it would make sense to create an artifact in services code base for small apps like that?

I knew it. I got this default value from mgm.services.core.user.credentials-hash-iterations of [ Services Configuration documentation]<INTERNAL_LINK>
We just need to add 1 arg to fix it.

Please be also aware that there is a feature team which works on the authorization and authentication concept, which would most likely not use shiro anymore.