Skip to content

Commit 4f76450

Browse files
authored
Update password_generator
1 parent e72d540 commit 4f76450

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

password_generator

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package git_projects.git_projects_java.src.password_generator;
2-
import java.security.SecureRandom;
32
import java.util.Scanner;
3+
import java.security.SecureRandom; // Import the SecrureRandom package
4+
// Here we are using 'SecureRandom' instead of 'Random' for more secure password
45

56

67

@@ -12,24 +13,37 @@ public class password_generator {
1213

1314
public static void main(String[] args) {
1415
Scanner sc = new Scanner(System.in);
16+
17+
//Taking input from an user using Scanner
1518
System.out.println("Enter the length of the password: ");
1619
int password_length = sc.nextInt();
20+
21+
// Calling an method from an Variable
1722
String password = generatepassword(password_length);
23+
24+
// Lets print the generated password
1825
System.out.println("The password: "+password);
1926
}
2027

21-
28+
// Create an method with a length parameter
2229
private static String generatepassword(int length)
2330
{
31+
32+
// StringBuilder to efficiently build the password character by character
2433
StringBuilder password = new StringBuilder();
2534

2635
for(int i=0;i<length;i++)
2736
{
37+
38+
// Generate an random index from the length of the pwd_characters
2839
char randomcharacter = char_set.charAt(random.nextInt(char_set.length()));
40+
41+
// append the generated random characters into 'password'
2942
password.append(randomcharacter);
3043

3144

3245
}
46+
// Returning password as an proper String
3347
return password.toString();
3448
}
3549
}

0 commit comments

Comments
 (0)