I am trying to develop user login/signup using JSP in MVC. The program will be doing a simple login, create and update for the user. In the model part I am supposed to return 0, 1, 2, 3 based on the following criteria.
0 if the user is validated successfully 1 if the user is validated successfully but has a weak password 2 if the user is validated successfully but has an expired password (over 1 year old) 3 if the user is not validated
Here is the code for the validate method which I have done till now,
public int Validate() {
try {
Class.forName(driverName).newInstance();
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
Connection connection = DriverManager.getConnection(dbURL,
username, password);
String verifyQuery = "SELECT COUNT(email), dateSet, strength FROM users WHERE email=? AND hashPassword=SHA2(CONCAT(?, salt), 256)";
PreparedStatement verify = connection.prepareStatement(verifyQuery);
verify.setString(1, email);
verify.setString(2, pass);
ResultSet verified = verify.executeQuery();
while (verified.next()) {
if (verified.getInt(1) == 1) {
email_db = verified.getString(2);
pass_db = verified.getString(3);
date = verified.getDate(5);
strength = verified.getString(6);
}
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (email_db.equals(email) && pass_db.equals(pass)) {
status = 0;
}
if (email_db.equals(email) && pass_db.equals(pass)
&& strength.equals("weak")) {
status = 1;
}
if (email_db.equals(email) && pass_db.equals(pass) && date> ){
}
return status;
}
I am confused about the Date part, any suggestions? Should I write a new method for the Date part?