Programmatically create Token

Does anyone of you know a way/trick to programmatically create a token by providing an admin username and password?

Thanks in advance