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