LoginAttemptBO loginAttemptBO = (LoginAttemptBO)appContext.getBean("loginAttemptBO");
OTPBO otpBO = (OTPBO)appContext.getBean("OTPBO");
int userid=0;
int empid=0;
InternalAccount ia = null;
String name = principal.getName();
ExternalAccount ea = loginAttemptBO.findAccountByNameExternal(name);
if(ea == null){
ia = loginAttemptBO.findAccountByNameInternal(name);
if(ia != null){
userid = 0;
empid = ia.getEmployeeId();
}
}else{
//external use case
userid = ea.getUserid();
empid = 0;
}
OTP indatabase = otpBO.findAccountByName(userid,empid);
//suppose user provided valid one-time-password
java.util.Date current_date = new java.util.Date();
java.sql.Timestamp current_timestamp = new java.sql.Timestamp(current_date.getTime());
long current_time = current_timestamp.getTime();
long db_time = indatabase.gettime().getTime();
long time_diff = current_time - db_time; //5 minutes = 5 * 60 * 1000 (ms) =300,000
// Need to be modified!!!
if(oneTimePassword.equals(indatabase.getotp()) && time_diff < 300000){
System.out.println("Ok!!!");
// delete the one time login entry
otpBO.delete(indatabase);
//set first time login to false
if(ea != null)
{
ea.setFirstTimeLogin(false);
externalAccountBO.update(ea);
}
if(ia != null)
{
ia.setFirstTimeLogin(false);
internalAccountBO.update(ia);
}
return "OTPValidationSuccess";
}else{