Ich entwickle eine Anwendung mit Hibernate.Wenn ich versuche, eine Login-Seite zu erstellen, entsteht das Problem der Sql-Injektion. Ich habe den folgenden Code:Wie kann SQL Injection im Ruhezustand verhindert werden?
@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;
}
}
Wie werde ich SQL-Injection in diesem Szenario zu verhindern Die Tabelle Syntax der Logininfo Tabelle erstellen ist wie folgt:?
create table login_info
(user_name varchar(16) not null primary key,
pass_word varchar(16) not null);
Bitte beziehen Sie sich auf diesen Link [1]: http://Stackoverflow.com/questions/4606505/prevention-against-sql-injection-in-hibernate –