generate random password in java

Solutions on MaxInterview for generate random password in java by the best coders in the world

showing results for - "generate random password in java"
Sophia
04 Jan 2018
1import java.util.Random;
2
3public class PasswordGenerator {
4	public static String generateRandomPassword(int len) {
5		String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghi"
6          +"jklmnopqrstuvwxyz!@#$%&";
7		Random rnd = new Random();
8		StringBuilder sb = new StringBuilder(len);
9		for (int i = 0; i < len; i++)
10			sb.append(chars.charAt(rnd.nextInt(chars.length())));
11		return sb.toString();
12	}
13}