-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.java
71 lines (69 loc) · 2.11 KB
/
login.java
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
/**
* SER-515 Login class implementing the implementation for login using facade
*
* @author Nirmit Agrawal, [email protected]
* @version 1.3
* @since 10-19-2022
*/
import java.io.File;
import java.util.Scanner;
public class login
{
int userType;
String name = "";
login()
{
userType = 0;
}
public int Login() {
System.out.println("Enter Username");
Scanner sc = new Scanner(System.in);
name = sc.nextLine();
System.out.println("Enter Password");
String password = sc.nextLine();
try {
userType = validation(password);
} catch (Exception e) {
throw new RuntimeException(e);
}
if(userType == -1)
{
System.out.println("Incorrect username or password");
System.exit(-1);
}
return userType;
}
public String userName()
{
return name;
}
public int validation(String password) throws Exception
{
String user , pass;
File buy = new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\BuyerInfo.txt");
Scanner buyer = new Scanner(buy);
File sell = new File("C:\\Users\\DELL\\Desktop\\Nirmit\\ASU\\SER 515\\Assignments\\Design Pattern - Individual\\SellerInfo.txt");
Scanner seller = new Scanner(sell);
while(buyer.hasNextLine())
{
String line = buyer.nextLine();
int index = line.indexOf(":");
user = line.substring(0,index);
pass = line.substring(index+1);
if(name.equals(user) && password.equals(pass))
{
return 0;
}
}
while(seller.hasNextLine()) {
String line = seller.nextLine();
int index = line.indexOf(":");
user = line.substring(0, index);
pass = line.substring(index + 1);
if(name.equals(user) && password.equals(pass)) {
return 1;
}
}
return -1;
}
}