File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ package password_generator ;
2+
3+ import java .util .Scanner ;
4+ import java .security .SecureRandom ;
5+
6+ public class password_generator_2 {
7+
8+ public String generatePassword (int length ) {
9+ String pwd_characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%&" ;
10+ SecureRandom random = new SecureRandom ();
11+ StringBuilder password = new StringBuilder ();
12+
13+ for (int i = 0 ; i < length ; i ++) {
14+ char randomChar = pwd_characters .charAt (random .nextInt (pwd_characters .length ()));
15+ password .append (randomChar );
16+ }
17+
18+ return password .toString ();
19+ }
20+ public static void main (String [] args ) {
21+ password_generator_2 generator = new password_generator_2 ();
22+ Scanner sc = new Scanner (System .in );
23+ System .out .println ();
24+ System .out .println ("Enter the length of the password: " );
25+ int passwordLength = sc .nextInt ();
26+ String password = generator .generatePassword (passwordLength );
27+ System .out .println ("______________________________________________" );
28+ System .out .println ();
29+ System .out .println ("The Password: " + password );
30+ System .out .println ("______________________________________________" );
31+ }
32+
33+ }
34+
You can’t perform that action at this time.
0 commit comments