-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAuthentication.java
More file actions
65 lines (48 loc) · 1.87 KB
/
Authentication.java
File metadata and controls
65 lines (48 loc) · 1.87 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
package JavaFundamentals;
import java.util.Scanner;
import java.util.ArrayList;
public class HelloWorld {
public static void main(String[] args) {
// Authentication for java
int type;
boolean isNotLogin = true;
boolean authenticated = false;
ArrayList <String> usernames = new ArrayList<>();
ArrayList <String> passwords = new ArrayList<>();
String username_input;
String password_input;
Scanner input = new Scanner(System.in);
while (isNotLogin) {
System.out.print("Would you like to create your account (Press 1 - Signup, 2 - Login) ? " );
type = input.nextInt();
input.nextLine();
if (type == 1) {
System.out.println("Initializing...");
System.out.println("You can now create your account!");
System.out.print("Enter your username: ");
username_input = input.nextLine();
usernames.add(username_input);
System.out.print("Enter your password: ");
password_input = input.nextLine();
passwords.add(password_input);
System.out.println("Sucessfully created your account!");
System.out.println("Heres your account, dont share it with your friends!");
System.out.println("username: " + username_input);
System.out.println("password: " + password_input);
}else if (type == 2) {
System.out.print("Enter your username: ");
username_input = input.nextLine();
System.out.print("Enter your password: ");
password_input = input.nextLine();
for (int i = 0; i < usernames.size(); i++) {
if (usernames.get(i).equals(username_input) && passwords.get(i).equals(password_input)) {
System.out.println("Welcome " + usernames.get(i));
authenticated = true;
}
}
if (!authenticated) System.out.println("Account was not found in the database!");
else isNotLogin = false;
}
}
}
}