-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
383 lines (336 loc) · 19.3 KB
/
Server.java
File metadata and controls
383 lines (336 loc) · 19.3 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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
package com.bkbank;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Date;
import java.io.*;
import java.nio.file.*;
import java.util.*;
import javax.net.ssl.HttpsURLConnection;
public class Server {
public static int Otp;
public static String Balance = "0.0";
public static List<String> FinalData = new ArrayList<String>();
public static String Transfer_UserName, Transfer_Phone_Number,account_number,transfer_amount;
public static int Current_Balance;
DatabaseMethods databaseMethods = new DatabaseMethods();
public static boolean sendOtp(String message, String number) {
int status;
boolean send;
try
{
final String API ="AoYciTbr8t7wlf5xR43U0g9QPFuaI6v1pKMBkyZmeqJXGODdNjYCFz1fEqw9klxDPiyIGbga6dXMK3ZS";
final String SEND_ID="FSTSMS";
final String MESSAGE = URLEncoder.encode(message, "UTF-8");
final String Language ="english";
final String Route = "p";
String Url="https://www.fast2sms.com/dev/bulk?authorization="+API+"&sender_id="+SEND_ID+"&message="+MESSAGE+"&language="+Language+"&route="+Route+"&numbers="+number;
URL url = new URL(Url);
HttpsURLConnection connection =(HttpsURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
connection.setRequestProperty("cache-control", "no-cache");
status = connection.getResponseCode();
StringBuffer response = new StringBuffer();
BufferedReader reading =new BufferedReader(new InputStreamReader(connection.getInputStream()));
while(true)
{
String line = reading.readLine();
if(line == null)
{
break;
}
response.append(line);
}
if(status == 200){
return true;
}
}catch (Exception e) {
e.printStackTrace();
}
return false;
}
public static boolean VerifyOtp(String user_input){
if(user_input.equals(String.valueOf(Otp))){
return true;
}
return false;
}
public static boolean Balance_Query(){
Server_methods server_methods = new Server_methods();
DatabaseMethods databaseMethods = new DatabaseMethods();
File file = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Balance.txt");
if(!file.exists()){
server_methods.Create_Balance_file();
System.out.println("Your Account Have No Balance :- 00");
return true;
}
if(file.exists()){
try {
java.util.List<java.lang.String> Data = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Balance.txt"));
java.util.List<java.lang.String> Data_key = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//User_key.txt"));
Balance = SecurityEncryptionDecryptionAES.decrypt(Data.get(0),Data_key.get(0));
} catch (Exception ignored){ }
return true;
}
return false;
}
public static boolean Money_Transition_history(String past_Balance,String Current_Balance, String Money,String Action){
Server_methods server_methods = new Server_methods();
DatabaseMethods databaseMethods = new DatabaseMethods();
try{
java.util.List<java.lang.String> Data_key = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//User_key.txt"));
long transition_id = methods.generateRandom(16);
int transitionId = (int) transition_id;
String data = Action + " on " + methods.current_time() + " Your Balance Will be " + "'" + past_Balance + "'" + " (Modified) to --> " + "'" + Current_Balance + "'" + " Your " + "'" + Action + "'" + " is " + "'" + Money + "'" + " . " + " Transition id will be :- " + "'" + Math.abs(transitionId) + "'";
methods.file_create_and_write(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number ,SecurityEncryptionDecryptionAES.encrypt(data,Data_key.get(0)) + "\n","Add_And_Withdraw_Money_Transition.txt");
return true;
} catch (Exception e){
System.out.println(e);
}
return false;
}
public static boolean Add_Money(){
Server_methods server_methods = new Server_methods();
DatabaseMethods databaseMethods = new DatabaseMethods();
File file = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Balance.txt");
File file_2 = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Add_And_Withdraw_Money_Transition.txt");
if(!file.exists()){
server_methods.Create_Balance_file();
}
if(!file_2.exists()){
server_methods.Create_Add_And_Withdraw_Money_Transition();
}
if(file.exists()){
try
{
java.util.List<java.lang.String> Data = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Balance.txt"));
java.util.List<java.lang.String> Data_key = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//User_key.txt"));
Balance = SecurityEncryptionDecryptionAES.decrypt(Data.get(0),Data_key.get(0));
System.out.println("\t\tAdd Amount\n\n");
System.out.println( "Your Current Balance is :- " + Balance);
methods.delay(2000);
int Current_Balance = Integer.parseInt(Balance);
String Current_B = Balance;
String Add_amount = methods.input("Invalid Input","Enter your amount : ");
try {
Current_Balance = Integer.parseInt(Add_amount) + Current_Balance;
}catch (Exception e){
System.out.println("WRONG INPUT !!! --> Enter a Number");
}
Balance = Integer.toString(Current_Balance);
FileWriter myWriter = new FileWriter(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Balance.txt");
myWriter.write(SecurityEncryptionDecryptionAES.encrypt(Balance,Data_key.get(0)));
myWriter.close();
methods.delay(1500);
System.out.println("Balance add Successfully !! :- " + Add_amount);
Money_Transition_history(Current_B,Integer.toString(Current_Balance),Add_amount,"Add Money");
return true;
} catch (IOException e)
{
e.printStackTrace();
}
} else {
methods.stop_code("405 -> Server on Heavy load try again after sometime");
}
return false;
}
public static boolean Withdraw_Money(){
Server_methods server_methods = new Server_methods();
DatabaseMethods databaseMethods = new DatabaseMethods();
File file = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Balance.txt");
File file_2 = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Add_And_Withdraw_Money_Transition.txt");
if(!file.exists()){
server_methods.Create_Balance_file();
System.out.println("\nYour Account have no Balance to Withdraw.");
return true;
}
if(!file_2.exists()){
server_methods.Create_Add_And_Withdraw_Money_Transition();
}
if(file.exists()){
try
{
java.util.List<java.lang.String> Data = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Balance.txt"));
java.util.List<java.lang.String> Data_key = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//User_key.txt"));
Balance = SecurityEncryptionDecryptionAES.decrypt(Data.get(0),Data_key.get(0));
System.out.println("\t\tWithdraw Amount\n\n");
System.out.println( "Your Current Balance is :- " + Balance);
methods.delay(1000);
int Current_Balance = Integer.parseInt(Balance);
String Current_B = Balance;
String Withdraw_amount = methods.input("Invalid Input","Enter your withdraw amount : ");
try {
if(Integer.parseInt(Withdraw_amount) <= Current_Balance){
Current_Balance = Current_Balance - Integer.parseInt(Withdraw_amount);
} else {
System.out.println("You enter a greater Amount than in your Amount !!");
return false;
}
}catch (Exception e){
System.out.println("WRONG INPUT !!! --> Enter a Number");
}
Balance = Integer.toString(Current_Balance);
FileWriter myWriter = new FileWriter(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Balance.txt");
myWriter.write(SecurityEncryptionDecryptionAES.encrypt(Balance,Data_key.get(0)));
myWriter.close();
methods.delay(1500);
System.out.println("Balance Withdraw Successfully !! :- " + Withdraw_amount);
Money_Transition_history(Current_B,Integer.toString(Current_Balance),Withdraw_amount,"Withdraw Money");
return true;
}
catch (IOException e)
{
e.printStackTrace();
}
} else {
methods.stop_code("405 -> Server on Heavy load try again after sometime");
}
return false;
}
public static boolean Money_Transition_history_show(){
Server_methods server_methods = new Server_methods();
DatabaseMethods databaseMethods = new DatabaseMethods();
File file_2 = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Add_And_Withdraw_Money_Transition.txt");
if(!file_2.exists()){
methods.clear_screen();
System.out.println("You Does not do any transition.");
return true;
}
try {
List<String> fileData = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Add_And_Withdraw_Money_Transition.txt"));
java.util.List<java.lang.String> Data_key = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//User_key.txt"));
if(SecurityEncryptionDecryptionAES.decrypt(fileData.get(0), Data_key.get(0)) == ""){
methods.clear_screen();
System.out.println("You Does not do any transition.");
}
System.out.println(" \n Please wait !!! (Load Your Transition history) \n");
methods.delay(2000);
methods.clear_screen();
int list_size = fileData.size();
System.out.println("Transition History Start :- (PRESS ENTER TO SEE MORE AND 'q' TO EXIT)");
methods.delay(800);
for (int i = 0; i < list_size; i++) {
Scanner scan = new Scanner(System.in);
System.out.print("\n::");
String str = scan.nextLine();
str = str.toLowerCase();
if(str.equals("q")){
methods.clear_screen();
System.out.println("\nYou Exit from Transition History.");
// methods.delay(6000);
return true;
}
methods.delay(400);
System.out.println( i + "). " + " " + SecurityEncryptionDecryptionAES.decrypt(fileData.get(i), Data_key.get(0)));
}
System.out.println("\n\nThis is the only transition history in your account. \n\n");
return true;
} catch (Exception e){
return false;
}
}
public static boolean Mini_Statement(){
Server_methods server_methods = new Server_methods();
DatabaseMethods databaseMethods = new DatabaseMethods();
File file_2 = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Add_And_Withdraw_Money_Transition.txt");
if(!file_2.exists()){
methods.clear_screen();
System.out.println("You Does not do any transition.");
return true;
}
try {
List<String> fileData = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Add_And_Withdraw_Money_Transition.txt"));
java.util.List<java.lang.String> Data_key = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//User_key.txt"));
if(SecurityEncryptionDecryptionAES.decrypt(fileData.get(0), Data_key.get(0)) == ""){
methods.clear_screen();
System.out.println("You Does not do any transition.");
return true;
}
System.out.println("\n\n\n(Load Your Mini Statement of Transition history) \n");
int list_size = fileData.size();
if(list_size > 10){
list_size = 10;
}
for (int i = 0; i < list_size; i++) {
methods.delay(400);
System.out.println( i + "). " + " " + SecurityEncryptionDecryptionAES.decrypt(fileData.get(i), Data_key.get(0)));
}
return true;
} catch (Exception e){
return false;
}
}
public static boolean Transfer_method(){
Server_methods server_methods = new Server_methods();
DatabaseMethods databaseMethods = new DatabaseMethods();
RegisterMethods registerMethods = new RegisterMethods();
System.out.println("Transfer Money Fast and Easy By Bk Bank. ");
account_number = methods.input("Invalid Input","Enter the Account Number of Other User : ");
boolean account_number_exist = registerMethods.checkUserAccountInDatabase(account_number);
File file = new File(databaseMethods.Database_path() + "\\" + LoginScreen.Account_Number + "\\Balance.txt");
if(!file.exists()){
server_methods.Create_Balance_file();
System.out.println("Your Account Have No Balance :- 00");
return true;
}else {
if (!account_number.equals(LoginScreen.Account_Number)) {
if (account_number_exist) {
try {
java.util.List<java.lang.String> AmountReceived = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + account_number + "//User_detail.txt"));
java.util.List<java.lang.String> DataKeyReceived = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + account_number + "//User_key.txt"));
java.util.List<java.lang.String> AmountSend = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//Balance.txt"));
java.util.List<java.lang.String> DataKeySend = Files.readAllLines(Paths.get(databaseMethods.Database_path() + "//" + LoginScreen.Account_Number + "//User_key.txt"));
Transfer_UserName = SecurityEncryptionDecryptionAES.decrypt(AmountReceived.get(0), DataKeyReceived.get(0));
Transfer_Phone_Number = SecurityEncryptionDecryptionAES.decrypt(AmountReceived.get(4), DataKeyReceived.get(0));
Transfer_Phone_Number = Transfer_Phone_Number.replaceAll("\\d(?=\\d{6})", "*");
String Balance = SecurityEncryptionDecryptionAES.decrypt(AmountSend.get(0), DataKeySend.get(0));
System.out.println("A.NO :- " + account_number);
System.out.println("User Name :- " + Transfer_UserName);
System.out.println("Phone No :- " + Transfer_Phone_Number);
System.out.println("\nCHECK TOP DEATIL ARE PROPER THAN TRANSFER MONEY.\n");
transfer_amount = methods.input("Invalid Input", "Enter Transfer Amount : ");
methods.clear_screen();
String pin = methods.input("Invalid Input", "\nEnter Your Pin : ");
if(pin.equals(LoginScreen.R_Pin)) {
if (Integer.parseInt(transfer_amount) <= Integer.parseInt(Balance)) {
if (server_methods.Cut_Balance(LoginScreen.Account_Number, Integer.parseInt(transfer_amount),LoginScreen.Account_Number)) {
if (server_methods.Transfer_Balance(account_number, Integer.parseInt(transfer_amount),LoginScreen.Account_Number)){
methods.delay(1000);
System.out.println("Transfer Amount Please wait !!");
methods.delay(3000);
methods.clear_screen();
System.out.println("Transfer Amount " + "'" + transfer_amount + "'" + " == " + "'" + LoginScreen.Account_Number + "'" + " ---> " + "'" + account_number + "'");
methods.delay(1000);
methods.clear_screen();
System.out.println("Transfer Amount " + "'" + transfer_amount + "'" + "Successfully !!");
return true;
} else {
System.out.println("\nError Occurred");
}
} else {
System.out.println("\nError Occurred");
}
} else {
System.out.println("You Have Enter a Greater amount that your Balance");
}
}else {
System.out.println("Pin does not match !!");
}
} catch (Exception ingnored){
System.out.println(ingnored);
return false;
}
} else {
System.out.println("CHECK NUMBER:- THESE " + "'" + account_number + "'" + " ACCOUNT ARE NOT EXIST.");
return false;
}
} else {
System.out.println("You Enter your own account");
return false;
}
}
return false;
}
}