Back to project page PasswordGen-LibGDX.
The source code is released under:
GNU General Public License
If you think the Android project PasswordGen-LibGDX listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.mygdx.generation; /*from ww w. java 2s . c o m*/ import java.util.ArrayList; import java.util.Random; public class GeneratePassword { private PasswordCharacters characters; private ArrayList<Character> password = new ArrayList<Character>(); private Random randCharacterSelection; public GeneratePassword(){ characters = new PasswordCharacters(); randCharacterSelection = new Random(); } public StringBuilder setPassword(){ StringBuilder sb = new StringBuilder(); for(int i=0; i < password.size(); i++){ sb.append(password.get(i)); } return sb; } public void createPassword(boolean lowercase, boolean uppercase, boolean specialChars, boolean numbers, int length) { int counter = 0; while(!(counter == length)){ Random id = new Random(); int randomChar = id.nextInt(4); if(lowercase && randomChar == 0){ int randomCharacter = randCharacterSelection.nextInt(characters.lowerCaseCharacters.length); password.add(characters.lowerCaseCharacters[randomCharacter]); counter++; } if(uppercase && randomChar == 1){ int randomCharacter = randCharacterSelection.nextInt(characters.upperCaseCharacters.length); password.add(characters.upperCaseCharacters[randomCharacter]); counter++; } if(specialChars && randomChar == 2){ int randomCharacter = randCharacterSelection.nextInt(characters.specialCharacters.length); password.add(characters.specialCharacters[randomCharacter]); counter++; } if(numbers && randomChar == 3){ int randomCharacter = randCharacterSelection.nextInt(characters.numberCharacters.length); password.add(characters.numberCharacters[randomCharacter]); counter++; } if(!numbers && !specialChars && !lowercase && !uppercase){ counter = length; } } } public void resetPassword() { password.clear(); } }