Authentication, Bcrypt and SessionsBCryptuser resourceuser creation routes and authorization routes, and the
act of authorization
POST /users - supplies information to create a user accountPOST /auth/login - supplies a username and password to authenticate
an account./auth is not part of the RESTful patten for creating, accessing,
updating and deleting user accounts. User accounts are a resource
that exists on their own. The /auth routes are routes that interact
with existing user resources to make sure users are who they say they
are./auth routes to handle users logging in and logging out to authenticate
and de-authenticate a user.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));
}