Skip to content

Commit 8943edd

Browse files
committed
Made changes to UserDatabase. Implemented UserExists, and UserCreator
1 parent e689731 commit 8943edd

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/main/java/UserCreator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import java.io.FileNotFoundException;
21

32
public interface UserCreator {
43
void createUser(String username, String password, String email);

src/main/java/UserDatabase.java

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,21 @@
22
import java.io.FileNotFoundException;
33
import java.io.PrintWriter;
44
import java.util.Scanner;
5-
public class UserDatabase implements UserRegPresenter, UserCreator{
5+
public class UserDatabase implements UserExists, UserCreator{
66
@Override
7-
public boolean UserExists() {
7+
public boolean UserExists(String username, String email) {
88
File accounts = new File("UserAccounts.csv");
9-
9+
try(Scanner x = new Scanner(accounts)){
10+
x.useDelimiter("\n");
11+
while(x.hasNext()) {
12+
String[] y = x.next().split(",");
13+
if(y[0].equals(username) || y[2].equals(email)){
14+
return true;
15+
}
16+
}
17+
}catch(FileNotFoundException e){
18+
System.out.println("Cannot find File");
19+
};
1020
return false;
1121
}
1222

@@ -17,7 +27,7 @@ public boolean UserExists() {
1727
public void createUser(String username, String password, String email) {
1828
File accounts = new File("UserAccounts.csv");
1929
try(PrintWriter out = new PrintWriter(accounts)){
20-
out.println(username + "," + password + "," + email + "," + "no" + "offline");
30+
out.println(username + "," + password + "," + email + "," + "no" + "," + "offline");
2131
out.flush();
2232
}catch (FileNotFoundException e){
2333
System.out.println("Error creating/writing to file");

src/main/java/UserExists.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public interface UserExists {
2+
boolean UserExists(String username, String password);
3+
}

0 commit comments

Comments
 (0)