File tree 1 file changed +8
-5
lines changed 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change 5
5
6
6
/*
7
7
Creates a random password from ASCII letters
8
+ Given password length bounds
8
9
9
10
author: AKS1996
10
- date: 2017-10-22
11
+ date: 2017-10-25
11
12
*/
12
13
13
14
class PasswordGen {
14
15
public static void main (String args []){
16
+ String password = generatePassword (8 ,16 );
17
+ System .out .print ("Password: " + password );
18
+ }
19
+
20
+ static String generatePassword (int min_length , int max_length ){
15
21
Random random = new Random ();
16
22
17
23
String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ;
@@ -27,16 +33,13 @@ public static void main(String args[]){
27
33
28
34
// Inbuilt method to randomly shuffle a elements of a list
29
35
Collections .shuffle (letters );
30
-
31
- int min_length = 8 ;
32
- int max_length = 16 ;
33
36
String password = "" ;
34
37
35
38
// Note that size of the password is also random
36
39
for (int i = random .nextInt (max_length -min_length ) + min_length ; i >0 ; --i ) {
37
40
password += letters .get (random .nextInt (letters .size ()));
38
41
}
39
42
40
- System . out . print ( "Password: " + password ) ;
43
+ return password ;
41
44
}
42
45
}
You can’t perform that action at this time.
0 commit comments