I was able to generate token when the customer tries to reset their password and send it to email. When I came back to the page and place the token I received in my email and tried to change the password, I am getting 'invalid token error'
I tried to debug through and came to know that it is not able to find the token, it meet the below if criteria at below line resulted in saying 'invalid token'.
Please advise.
if (fpst == null) {
response.addErrorCode("invalidToken");
}
Code: Select all
public GenericResponse resetPasswordUsingToken(String username, String token, String password, String confirmPassword) {
GenericResponse response = new GenericResponse();
Customer user = null;
if (username != null) {
user = customerDao.readCustomerByUsername(username);
}
checkUser(user, response);
checkPassword(password, confirmPassword, response);
if (token == null || "".equals(token)) {
response.addErrorCode("invalidToken");
}
ForgotPasswordSecurityToken fpst = null;
if (! response.getHasErrors()) {
token = token.toLowerCase();
fpst = forgotPasswordSecurityTokenDao.readToken(passwordEncoder.encodePassword(token,null));
if (fpst == null) {
response.addErrorCode("invalidToken");
} else if (fpst.isTokenUsedFlag()) {
response.addErrorCode("tokenUsed");
} else if (isTokenExpired(fpst)) {
response.addErrorCode("tokenExpired");
}
}