-
Notifications
You must be signed in to change notification settings - Fork 44
/
Authentication.java
59 lines (59 loc) · 1.21 KB
/
Authentication.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
import java.util.Scanner;
class Main{
public static void main(String []args){
String name;
String pass;
Scanner scanner = new Scanner(System.in);
System.out.print("Enter Usename: ");
name=scanner.nextLine();
System.out.print("Enter your password: ");
pass=scanner.nextLine();
Authentication a=new Authentication();
User user = new User();
user.setUsername(name);
user.setPassword(pass);
try{
a.isAuthentication(user);
}catch(Loginfail loginfail){
loginfail.printStackTrace();
}
}
}
class Authentication{
public boolean isAuthentication(User user) throws Loginfail{
if(user.getUsername().equals(user.getPassword())){
System.out.println("Login Successfull");
return true;
}
else{
throw new Loginfail ("Invalid username or password");
}
}
}
class Loginfail extends Exception{
String msg=null;
public Loginfail(){
}
public Loginfail(String msg){
this.msg=msg;
}
public String toString(){
return msg;
}
}
class User{
String username;
String password;
String getUsername(){
return username;
}
void setUsername(String username){
this.username=username;
}
String getPassword(){
return password;
}
void setPassword(String password){
this.password=password;
}
}