0
我有一个JSF + JPA Web应用程序,其登录机制如下。在JSF + JPA web应用程序中优化身份验证
- 用户名是加密
- 密码进行散列
- 使用Jasypt
- 当用户尝试登录,所有用户都采取了一个循环。
- 解密每个用户的用户名并与输入的用户名匹配。
- 如果匹配,密码将被散列,并使用存储的hased密码进行检查。
在用户数量预计很高的另一个应用程序中,我从前三个字母中过滤用户,将其存储为单独的字段。
如果您能指出我使用的次优方法并引导我采取正确行动,我将非常感谢。
的控制器关心的加密列
import java.io.Serializable;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import org.jasypt.util.password.BasicPasswordEncryptor;
import org.jasypt.util.text.BasicTextEncryptor;
@ManagedBean
@SessionScoped
public class SecurityController implements Serializable {
private static final long serialVersionUID = 1L;
public SecurityController() {
}
public String encrypt(String word) {
BasicTextEncryptor en = new BasicTextEncryptor();
en.setPassword("health");
try {
return en.encrypt(word);
} catch (Exception ex) {
return null;
}
}
public String hash(String word) {
try {
BasicPasswordEncryptor en = new BasicPasswordEncryptor();
return en.encryptPassword(word);
} catch (Exception e) {
return null;
}
}
public boolean matchPassword(String planePassword, String encryptedPassword) {
BasicPasswordEncryptor en = new BasicPasswordEncryptor();
return en.checkPassword(planePassword, encryptedPassword);
}
public String decrypt(String word) {
BasicTextEncryptor en = new BasicTextEncryptor();
en.setPassword("health");
try {
return en.decrypt(word);
} catch (Exception ex) {
return null;
}
}
}
这他怎么检查autnetication。
private boolean checkUsers() {
String temSQL;
temSQL = "SELECT u FROM WebUser u WHERE u.retired = false";
List<WebUser> allUsers = getFacede().findBySQL(temSQL);
for (WebUser u : allUsers) {
if (getSecurityController().decrypt(u.getName()).equalsIgnoreCase(userName)) {
if (getSecurityController().matchPassword(passord, u.getWebUserPassword())) {
setLoggedUser(u);
setLogged(Boolean.TRUE);
setActivated(u.isActivated());
setRole(u.getRole());
getMessageController().setDefLocale(u.getDefLocale());
getMeController().createMenu();
getWebUserBean().setLoggedUser(u);
UtilityController.addSuccessMessage("Logged successfully");
return true;
}
}
}
return false;
}
第一个问题,为什么要加密用户名? –
虽然可以读取数据库的攻击者可能会拦截未加密的用户名。 –