use of org.maxkey.password.onetimepwd.OneTimePassword in project MaxKey by dromara.
the class InMemoryOtpTokenStore method store.
@Override
public void store(UserInfo userInfo, String token, String receiver, String type) {
DateTime currentDateTime = new DateTime();
OneTimePassword otp = new OneTimePassword();
otp.setId(userInfo.getUsername() + "_" + type + "_" + token);
otp.setType(type);
otp.setUsername(userInfo.getUsername());
otp.setToken(token);
otp.setReceiver(receiver);
otp.setCreateTime(currentDateTime.toString("yyyy-MM-dd HH:mm:ss"));
optTokenStore.put(otp.getId(), otp);
}
use of org.maxkey.password.onetimepwd.OneTimePassword in project MaxKey by dromara.
the class RedisOtpTokenStore method validate.
@Override
public boolean validate(UserInfo userInfo, String token, String type, int interval) {
RedisConnection conn = connectionFactory.getConnection();
OneTimePassword otp = (OneTimePassword) conn.getObject(PREFIX + userInfo.getUsername() + "_" + type + "_" + token);
conn.delete(PREFIX + userInfo.getUsername() + "_" + type + "_" + token);
conn.close();
if (otp != null) {
return true;
}
return false;
}
use of org.maxkey.password.onetimepwd.OneTimePassword in project MaxKey by dromara.
the class RedisOtpTokenStore method store.
@Override
public void store(UserInfo userInfo, String token, String receiver, String type) {
DateTime currentDateTime = new DateTime();
OneTimePassword otp = new OneTimePassword();
otp.setId(userInfo.getUsername() + "_" + type + "_" + token);
otp.setType(type);
otp.setUsername(userInfo.getUsername());
otp.setToken(token);
otp.setReceiver(receiver);
otp.setCreateTime(currentDateTime.toString("yyyy-MM-dd HH:mm:ss"));
RedisConnection conn = connectionFactory.getConnection();
conn.setexObject(PREFIX + otp.getId(), validitySeconds, otp);
conn.close();
}
use of org.maxkey.password.onetimepwd.OneTimePassword in project MaxKey by dromara.
the class InMemoryOtpTokenStore method validate.
@Override
public boolean validate(UserInfo userInfo, String token, String type, int interval) {
OneTimePassword otp = optTokenStore.getIfPresent(userInfo.getUsername() + "_" + type + "_" + token);
if (otp != null) {
DateTime currentdateTime = new DateTime();
DateTime oneCreateTime = DateTime.parse(otp.getCreateTime(), DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss"));
Duration duration = new Duration(oneCreateTime, currentdateTime);
int intDuration = Integer.parseInt(duration.getStandardSeconds() + "");
logger.debug("validate duration " + intDuration);
logger.debug("validate result " + (intDuration <= interval));
if (intDuration <= interval) {
return true;
}
}
return false;
}
Aggregations