Skip to content

Commit 3abf1f5

Browse files
author
Akshay Sharma
authored
Update PasswordGen.java
separated main and generatePassword function
1 parent 1c34220 commit 3abf1f5

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Others/PasswordGen.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55

66
/*
77
Creates a random password from ASCII letters
8+
Given password length bounds
89
910
author: AKS1996
10-
date: 2017-10-22
11+
date: 2017-10-25
1112
*/
1213

1314
class PasswordGen {
1415
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){
1521
Random random = new Random();
1622

1723
String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -27,16 +33,13 @@ public static void main(String args[]){
2733

2834
// Inbuilt method to randomly shuffle a elements of a list
2935
Collections.shuffle(letters);
30-
31-
int min_length = 8;
32-
int max_length = 16;
3336
String password = "";
3437

3538
// Note that size of the password is also random
3639
for(int i = random.nextInt(max_length-min_length) + min_length; i>0; --i) {
3740
password += letters.get(random.nextInt(letters.size()));
3841
}
3942

40-
System.out.print("Password: " + password);
43+
return password;
4144
}
4245
}

0 commit comments

Comments
 (0)