-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUser.java
More file actions
165 lines (150 loc) · 4.78 KB
/
User.java
File metadata and controls
165 lines (150 loc) · 4.78 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment.pkg1;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
/**
*
* @author ee14ssr
*/
public class User {
private String Name;
private String Role;
private String Password;
private String Filename;
public User() {
Role = "Bank Employee";
Filename = "login.txt";
}
public void User() {
}
public boolean isRegistered(String newName, String newPassword) {
boolean isRegistered;
Name = newName;
Password = newPassword;
FileWriter writer;
try {
writer = new FileWriter(Filename, true);
writer.write(Name + System.getProperty("line.separator"));
writer.write(Password + System.getProperty("line.separator"));
writer.write("##" + System.getProperty("line.separator"));
isRegistered = true;
writer.flush();
writer.close();
writer = null;
} catch (IOException ioe) {
isRegistered = false;
}
return isRegistered;
}
public boolean isUser(String newName, String newPassword) {
Name = newName;
Password = newPassword;
boolean isNameFound = false;
boolean isPasswordFound = false;
boolean isFound = false;
int NameLocator = 0;
int i = 0;
String record;
FileReader reader;
try {
reader = new FileReader(Filename);
BufferedReader bin = new BufferedReader(reader);
record = new String();
while ((record = bin.readLine()) != null) {
i++;
if (Name.contentEquals(record)) {
isNameFound = true;
NameLocator = i;
}
if (i == NameLocator + 1) {
if (Password.contentEquals(record)) {
isPasswordFound = true;
}
}
}
bin.close();
bin = null;
if (isNameFound == true && isPasswordFound == true) {
isFound = true;
}
} catch (IOException ioe) {
isFound = false;
}
return isFound;
}
public void changePassword(String newName, String oldPassword, String newPassword) {
Name = newName;
int PasswordLocator = 0;
int i = 0;
String record;
FileReader reader;
FileWriter writer;
try {
PrintWriter tempwriter = new PrintWriter(new BufferedWriter(new FileWriter("login.temp")));
writer = new FileWriter(Filename, true);
reader = new FileReader(Filename);
BufferedReader bin = new BufferedReader(reader);
record = new String();
while ((record = bin.readLine()) != null) {
i++;
if (oldPassword.contentEquals(record)) {
record.replace(oldPassword, newPassword);
}
}
writer.flush();
writer.close();
writer = null;
bin.close();
bin = null;
} catch (IOException ioe) {
}
}
public boolean isEmployee(String newName) {
Name = newName;
boolean isEmployeeFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Employee")) {
isEmployeeFound = true;
}
return isEmployeeFound;
}
public boolean isAdministrator(String newName) {
Name = newName;
boolean isAdministratorFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Administrator")) {
isAdministratorFound = true;
}
return isAdministratorFound;
}
public boolean isManager(String newName) {
Name = newName;
boolean isManagerFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Manager")) {
isManagerFound = true;
}
return isManagerFound;
}
public boolean isAdvisor(String newName) {
Name = newName;
boolean isAdvisorFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Advisor")) {
isAdvisorFound = true;
}
return isAdvisorFound;
}
public boolean isClient(String newName) {
Name = newName;
boolean isClientFound = false;
if (Name.substring(Name.lastIndexOf(":") + 1).matches("Client")) {
isClientFound = true;
}
return isClientFound;
}
}