Created
December 2, 2018 16:12
-
-
Save sXakil/05793eec661b1d2fa83aa7c2d26d79f4 to your computer and use it in GitHub Desktop.
Generate a random alphaneumeric password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.ums.pau.resources; | |
import java.security.SecureRandom; | |
import java.util.ArrayList; | |
import java.util.List; | |
public class GenPass { | |
private String str; | |
private StringBuilder sb; | |
private List<Integer> l; | |
public GenPass() { | |
this.l = new ArrayList<>(); | |
this.sb = new StringBuilder(); | |
buildPassword(); | |
} | |
private void buildPassword() { | |
for (int i = 48; i <= 122; i++) { | |
if ((i > 57 && i < 65) || (i > 90 && i < 97)) | |
continue; | |
l.add(i); | |
} | |
for (int i = 0; i < 8; i++) { | |
int randInt = l.get(new SecureRandom().nextInt(62)); | |
sb.append((char) randInt); | |
} | |
str = sb.toString(); | |
} | |
public String getString() { | |
return str; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment