seattle-java-401d1

CF Authentication, Bcrypt and Sessions

Resources

Learning Objectives

Lecture Outline

Code Samples

public class SessionServlet extends HttpServlet {
  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
                  throws ServletException, IOException {
          String attributeName = req.getParameter("attributeName");
          String attributeValue = req.getParameter("attributeValue");
          req.getSession().setAttribute(attributeName, attributeValue);
          resp.sendRedirect(req.getContextPath() + "/");
  }
}
@Test
public void testCorectPass() {
    String password = "password";
    String wrongPassword = "nopenope";
    String hashed = BCrypt.hashpw(password, BCrypt.gensalt(12));

    assertTrue(BCrypt.checkpw(password, hashed));
    assertFalse(BCrypt.checkpw(wrongPassword, hashed));
}