Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.software.berater.test;
- import java.util.ArrayList;
- import java.util.List;
- /**
- * Created by bileser on 06.10.15.
- */
- public class RandomPasswordGenerator {
- private String newPassword = "";
- private static final String DIGITS = "123456789";
- private static final String LOCASE_CHARACTERS = "abcdefghjkmnpqrstuvwxyz";
- private static final String UPCASE_CHARACTERS = "ABCDEFGHJKMNPQRSTUVWXYZ";
- private static final String SYMBOLS = "-_;:()%&$§";
- private static java.util.Random r = new java.util.Random();
- public String getNewPassword(int maxLength) {
- if (maxLength < 4){
- maxLength = 4;
- }
- List<String> pools = new ArrayList<String>();
- pools.add(RandomPasswordGenerator.DIGITS);
- pools.add(RandomPasswordGenerator.LOCASE_CHARACTERS);
- pools.add(RandomPasswordGenerator.UPCASE_CHARACTERS);
- pools.add(RandomPasswordGenerator.SYMBOLS);
- StringBuilder sb = new StringBuilder();
- while (sb.length() != maxLength){
- for (String pool : pools){
- boolean takeChar = false;
- char charCandidate = 'a';
- while (!takeChar){
- char[] charPool = pool.toCharArray();
- charCandidate = charPool[r.nextInt(charPool.length)];
- if (charCandidate == 'l' && sb.toString().contains("1")){
- } else if (charCandidate == 'O' && sb.toString().contains("0")){
- } else {
- takeChar = true;
- }
- }
- sb.append(charCandidate);
- if (sb.length() == maxLength){
- return sb.toString();
- }
- }
- }
- return null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement