Repository navigation
Expand file tree
/
Copy pathCredentialsGenerator.java
More file actions
76 lines (53 loc) · 1.83 KB
/
Copy pathCredentialsGenerator.java
File metadata and controls
76 lines (53 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package com.OOPs.Lab;
import java.util.Random;
public class CredentialsGenerator {
private Employee employee;
private String generatedEmailID;
private char[] generatedPassword = new char[8];
public CredentialsGenerator(Employee employee) {
this.employee = employee;
}
public void generateEmailID() {
String departShortName = getDepartShortName();
String emailID = employee.getFirstName().toLowerCase()
+ "." + employee.getLastName().toLowerCase()
+ "@" + departShortName + ".gl.com";
// employee.setEmailID(emailID);
this.generatedEmailID = emailID;
}
private String getDepartShortName() {
String departmentName = employee.getDepartment();
if (departmentName.equals("Technical")) {
return "tech";
}else if (departmentName.equals("Admin")) {
return "admin";
}else if (departmentName.equals("Human Resource")) {
return "hr";
}else if (departmentName.equals("Legal")) {
return "lgl";
}
return "";
}
public void generatePassword() {
String capitalLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
String smallLetters = "abcdefghijklmnopqrstuvwxyz";
String numbers = "0123456789";
String specialCharacters = "!@#$%^&*_=+-/.?<>)";
String allValues = capitalLetters + smallLetters
+ numbers + specialCharacters;
Random randomObj = new Random();
for (int i=0; i < 8; i++) {
int boundValue = allValues.length();
int randomIndex = randomObj.nextInt(boundValue);
char randomChar = allValues.charAt(randomIndex);
this.generatedPassword[i] = randomChar;
}
}
public void showCredentials() {
System.out.print("Dear " + employee.getFirstName() + ", ");
System.out.println("Your generated credentials are as follows");
System.out.println("Email ID: " + generatedEmailID);
System.out.print("Password: ");
System.out.println(generatedPassword);
}
}