@Test public void canGenerateRandomPassword() { String randomPassword1 = passwordUtil.generateRandomPassword(16); String randomPassword2 = passwordUtil.generateRandomPassword(16); assertThat(randomPassword1).hasSize(16); assertThat(randomPassword2).hasSize(16); assertThat(randomPassword1).isNotEqualTo(randomPassword2); }
public String generateRandomPassword(int length) { StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { int c = random.nextInt(62); if (c <= 9) { sb.append(String.valueOf(c)); } else if (c < 36) { sb.append((char) ('a' + c - 10)); } else { sb.append((char) ('A' + c - 36)); } } return sb.toString(); }
PasswordUtil implements Serializable { public String generateRandomPassword(int length) { StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { int c = random.nextInt(62); if (c <= 9) { sb.append(String.valueOf(c)); } else if (c < 36) { sb.append((char) ('a' + c - 10)); } else { sb.append((char) ('A' + c - 36)); } } return sb.toString(); } }
PasswordUtil implements Serializable { public String generateRandomPassword(int length) { StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { int c = random.nextInt(62); if (c <= 9) { sb.append(String.valueOf(c)); } else if (c < 36) { sb.append((char) ('a' + c - 10)); } else { sb.append((char) ('A' + c - 36)); } } return sb.toString(); } PasswordUtil(); protected  PasswordUtil(int cost); }
PasswordUtil implements Serializable { public String generateRandomPassword(int length) { StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { int c = random.nextInt(62); if (c <= 9) { sb.append(String.valueOf(c)); } else if (c < 36) { sb.append((char) ('a' + c - 10)); } else { sb.append((char) ('A' + c - 36)); } } return sb.toString(); } PasswordUtil(); protected  PasswordUtil(int cost); String generateRandomPassword(int length); String hash(char[] password); boolean authenticate(char[] password, String passwordHash); }
PasswordUtil implements Serializable { public String generateRandomPassword(int length) { StringBuilder sb = new StringBuilder(length); for (int i = 0; i < length; i++) { int c = random.nextInt(62); if (c <= 9) { sb.append(String.valueOf(c)); } else if (c < 36) { sb.append((char) ('a' + c - 10)); } else { sb.append((char) ('A' + c - 36)); } } return sb.toString(); } PasswordUtil(); protected  PasswordUtil(int cost); String generateRandomPassword(int length); String hash(char[] password); boolean authenticate(char[] password, String passwordHash);  }