2
2
import java .io .FileNotFoundException ;
3
3
import java .io .PrintWriter ;
4
4
import java .util .Scanner ;
5
- public class UserDatabase implements UserRegPresenter , UserCreator {
5
+ public class UserDatabase implements UserExists , UserCreator {
6
6
@ Override
7
- public boolean UserExists () {
7
+ public boolean UserExists (String username , String email ) {
8
8
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
+ };
10
20
return false ;
11
21
}
12
22
@@ -17,7 +27,7 @@ public boolean UserExists() {
17
27
public void createUser (String username , String password , String email ) {
18
28
File accounts = new File ("UserAccounts.csv" );
19
29
try (PrintWriter out = new PrintWriter (accounts )){
20
- out .println (username + "," + password + "," + email + "," + "no" + "offline" );
30
+ out .println (username + "," + password + "," + email + "," + "no" + "," + " offline" );
21
31
out .flush ();
22
32
}catch (FileNotFoundException e ){
23
33
System .out .println ("Error creating/writing to file" );
0 commit comments