-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathUserdef.java
More file actions
34 lines (34 loc) · 888 Bytes
/
Userdef.java
File metadata and controls
34 lines (34 loc) · 888 Bytes
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
import java.util.Scanner;
class InvalidAccess extends Exception{
public InvalidAccess(String s){
super(s);
}
}
public class Userdef
{
public static void main(String args[])
{
String username = "user1";
String password = "pass123";
Scanner sc = new Scanner(System.in);
System.out.print("Enter username: ");
String user = sc.nextLine();
System.out.print("Enter password: ");
String pass = sc.nextLine();
try
{
if((user.equals(username)) && (pass.equals(password)))
{
System.out.println("ACCESS GRANTED");
}
else
{
throw new InvalidAccess("Invalid Username or Password");
}
}
catch(InvalidAccess e)
{
System.out.println(e.getMessage());
}
}
}