我正在使用hibernate开发一个应用程序.当我尝试创建一个登录页面时,出现了Sql Injection的问题.我有以下代码:
@Component
@Transactional(propagation = Propagation.SUPPORTS)
public class LoginInfoDAOImpl implements LoginInfoDAO{
@Autowired
private SessionFactory sessionFactory;
@Override
public LoginInfo getLoginInfo(String userName,String password){
List<LoginInfo> loginList = sessionFactory.getCurrentSession().createQuery("from LoginInfo where userName='"+userName+"' and password='"+password+"'").list();
if(loginList!=null )
return loginList.get(0);
else return null;
}
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下如何防止Sql注入?loginInfo表的create table语法如下:
create table login_info
(user_name varchar(16) not null primary key,
pass_word varchar(16) not null);
Run Code Online (Sandbox Code Playgroud) 我有一个Java应用程序,它大量使用大文件,读取,处理并通过SolrEmbeddedServer(http://lucene.apache.org/solr/).
其中一个函数执行基本的HTML转义:
private String htmlEscape(String input)
{
return input.replace("&", "&").replace(">", ">").replace("<", "<")
.replace("'", "'").replaceAll("\"", """);
}
Run Code Online (Sandbox Code Playgroud)
在分析应用程序时,该程序在此功能中花费大约58%的时间,替换中总共占47%,在replaceAll中占11%.
现在,Java取代速度是否缓慢,或者我是否在正确的道路上,我是否应该认为该程序足够高效,以便在Java中出现瓶颈,而不是在我的代码中?(或者我替换错了?)
提前致谢!