-
Notifications
You must be signed in to change notification settings - Fork 0
/
AccountHelper.java
84 lines (79 loc) · 2.38 KB
/
AccountHelper.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//AccountHelper assits with LoginLayout and CreateUserLayout
//AccountHelper stores user credentials and also is where new account credentials are sent to the database
//LoginLayout checks userExists() and isValidPassword() for login
//Error messages are also stored and processed
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.GridLayout;
import javax.swing.border.LineBorder;
import java.util.*;
import java.util.HashMap;
public class AccountHelper
{
public static HashMap<String, String> userCredentials = new HashMap<String, String>();
public static boolean createUser(String userName, String password, String chk_password) // return boolean if successful account creation
{
String[] errMsgs = new String[4];
//If user Exists
if(userExists(userName)){
errMsgs[0] = "User Name Already Exists";
}
else if("".equals(password))
{
errMsgs[1] = "Invalid Password";
}
else if(password.equals(chk_password))
{
userCredentials.put(userName, password);
errMsgs[0] = "User Created";
CreateUserLayout.errGenerator(errMsgs);
return true;
}
else
{
errMsgs[1] = "Passwords do not match";
}
CreateUserLayout.errGenerator(errMsgs);
return false;
/*
if(userExists(array[0].getText())){
System.out.println(array[0].getText());
return false;
}
if(!array[1].getText() .equals(""))
{
System.out.println(array[0].getText());
System.out.println(array[1].getText());
if(!array[2].getText().equals(""))
{
if(array[1].getText().equals( array[2].getText()))//for some reason this is true even if !array[1].equals array[2]
{
System.out.println(array[2].getText());
userCredentials.put(array[0].getText(), array[1].getText());
}
}
}
else
return false;
CreateUserLayout.errGenerator(usernameErr, passwordErr, confirmPasswordErr, emailErr);
return true;*/
}
public static void init(){
userCredentials.put("Joe", "pw");
userCredentials.put("Sam", "oq");
}
public static boolean userExists(String userName){
return userCredentials.containsKey(userName);
}
public static boolean isVaildPassword(String userName, String password){
if(userCredentials.containsKey(userName))
{
return userCredentials.get(userName).equals( password );
}
else
{
return false;
}
}
}