fixes bug#21867
qua: dev: git-svn-id: http://desenvolvimento.rjconsultores.com.br/repositorio/sco/AdmVenta/Model/trunk/modelWeb@106131 d1611594-4594-4d17-8e1d-87c2c4800839master
parent
f1531087de
commit
d53991d162
|
@ -0,0 +1,55 @@
|
|||
package com.rjconsultores.ventaboletos.utilerias;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import com.rjconsultores.ventaboletos.utilerias.DateUtil;
|
||||
|
||||
|
||||
|
||||
|
||||
public class PasswordHelper {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(PasswordHelper.class);
|
||||
|
||||
private static PasswordHelper instance;
|
||||
private final int MM_MAX = 10;
|
||||
|
||||
private String password = "";
|
||||
private Date passwordCreated;
|
||||
|
||||
public static PasswordHelper getInstance() {
|
||||
if (instance == null)
|
||||
instance = new PasswordHelper();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public String generateRandomPassword() {
|
||||
int size = 8;
|
||||
String capLetter = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||
String numbers = "01234567890123456789";
|
||||
String finalString = capLetter + numbers;
|
||||
|
||||
Random random = new Random();
|
||||
char[] charPassword = new char[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
charPassword[i] = finalString.charAt(random.nextInt(finalString.length()));
|
||||
}
|
||||
password = String.valueOf(charPassword);
|
||||
passwordCreated = DateUtil.somarMinutos(new Date(), MM_MAX);
|
||||
log.info("Gerada Senha de Instalação Valida até: " + passwordCreated.toString());
|
||||
return password;
|
||||
}
|
||||
|
||||
public boolean isValidPassword(String myPassword) {
|
||||
return !StringUtils.isBlank(myPassword) &&
|
||||
!StringUtils.isBlank(password) &&
|
||||
password.equals(myPassword) &&
|
||||
DateUtil.compareDate(new Date(), passwordCreated) < 0;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue