0

i have a login java servlet that will select the username and password from database table and compare them with form data, then will redirects the user to the next page if entered parameters are correct, what i want is to passe the username and password select from the DB to the page as parameters but as json: {username:"select username", password:"select password"}, so whet it redirects to the account.jsp page it passes the json with it so i can use it later on the json page.

here is my code, can any one please tell me how to do that:

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    resp.setContentType("text/html");

    String login = req.getParameter("login");
    String password = req.getParameter("password");

    try {
        Class.forName("com.mysql.jdbc.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/steg","root","");
        PreparedStatement pst = conn.prepareStatement("Select * from Employe where login=? and password=?");

        pst.setString(1, login);
        pst.setString(2, password);
        ResultSet rs = pst.executeQuery();

        if (rs.next()) {
            HttpSession session=req.getSession();
            session.setAttribute("login",login);
            session.setAttribute("password",password);

            req.setAttribute("liste",liste);
            req.setAttribute(login, rs);

            resp.sendRedirect("account.jsp");
        } else {
            resp.sendRedirect("erreur.jsp");
        }
    } catch (ClassNotFoundException | SQLException e) {
        e.printStackTrace();
    }
}
Jake Miller
  • 2,034
  • 1
  • 17
  • 38
  • You should not be storing plain text passwords. You should be encrypting them using a standardized hashing algorithm with a salt. Look into encrypting passwords with BCrypt. – Jake Miller Apr 08 '18 at 21:45
  • @JakeMiller [bcrypt](https://en.wikipedia.org/wiki/Bcrypt) is not encryption, it is a [password hashing function](https://en.wikipedia.org/wiki/Cryptographic_hash_function#Password_verification). – zaph Apr 09 '18 at 04:52
  • @zaph My mistake using improper terminology. Changed my answer. – Jake Miller Apr 09 '18 at 05:10

0 Answers0