Generate a Secure Random Password in Java

Recently I had to generate a random password that met the password security requirements of AWS – 32 characters in length with 1 special character and 1 digit.

Turned out to be a simple enough thing to do in java.

String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789~`!@#$%^&*()-_=+[{]}\\|;:\'\",<.>/?";
String password = RandomStringUtils.random(32, characters);

Just make sure you include the Apache Commons Lang

Source: Generate a Secure Random Password in Java with Minimum Special Character Requirements

Advertisements

Published by

Alan Feekery

Developer, Gamer, Musician, Cyclist and big Motorsport fan... enjoys the odd cup of coffee :)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s