private String login(HttpServletRequest request, HttpServletResponse response) {
      List<String> errors = new ArrayList<String>();
       request.setAttribute("errors", errors);
      Â
      String username = request.getParameter("username");
      String password = request.getParameter("password");
     Â
// Basic input validation
      if(username.matches("[\\w]*")) errors.add("Incorrect user name format.");
      if(password.matches("[\\w]*")) errors.add("Incorrect password format.");
     Â
      if(errors.size() > 0) return "error.do";
     Â
      UserBean dbUser = this.userDAO.lookup(username);
      if(!dbUser.checkPassword(password)) {
         errors.add("Passwords do not match.");
         return "error.do";
      }
     Â
      Cookie userCookie = new Cookie("user", username); // Create a cookie that contains the username
      response.addCookie(userCookie); // Send the cookie information to the client
     Â
      return "welcome.do";
}
|