thelittlewozniak

Untitled

Dec 4th, 2018
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.14 KB | None | 0 0
  1. package betaboutique.servlets.client;
  2.  
  3. import java.io.IOException;
  4. import java.io.PrintWriter;
  5.  
  6. import javax.servlet.ServletConfig;
  7. import javax.servlet.ServletContext;
  8. import javax.servlet.ServletException;
  9. import javax.servlet.annotation.WebServlet;
  10. import javax.servlet.http.HttpServlet;
  11. import javax.servlet.http.HttpServletRequest;
  12. import javax.servlet.http.HttpServletResponse;
  13.  
  14. import betaboutique.javabean.Client;
  15.  
  16. /**
  17.  * Servlet implementation class ServletAuthentification2
  18.  */
  19. @WebServlet("/ServletAuthentification6")
  20. public class ServletAuthentification6 extends HttpServlet {
  21.     private static final long serialVersionUID = 1L;
  22.     String id=null;
  23.     String mdp=null;
  24.     String email=null;
  25.        
  26.     /**
  27.      * @see HttpServlet#HttpServlet()
  28.      */
  29.     public void init()
  30.     {
  31.         ServletConfig config = getServletConfig();
  32.         id = config.getInitParameter("defautIdentifiant");
  33.         mdp = config.getInitParameter("defautMotDePasse");
  34.         email=getServletContext().getInitParameter("emailAdministrateur");
  35.     }
  36.     /**
  37.      * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  38.      */
  39.     public void doGet(HttpServletRequest request, HttpServletResponse
  40.               response)throws ServletException, IOException
  41.                   {
  42.                       //identifiant et mot de passe
  43.                      
  44.                       //l’identifiant/login est récupéré dans la requête
  45.                       String identifiant=request.getParameter("identifiant");
  46.                       //le mot de passe est récupéré dans la requête
  47.                       String motdepasse=request.getParameter("motdepasse");
  48.                       //flux de sortie
  49.                       PrintWriter out=response.getWriter();
  50.                       if(request.getParameter("valider")!=null)
  51.                       {
  52.                 if(identifiant==null) //pas d’identifiant
  53.                           {
  54.                               out.println("Authentification incorrecte !");
  55.                           }
  56.                 if(motdepasse==null) //pas de mot de passe
  57.                           {
  58.                               out.println("Authentification incorrecte !");
  59.                           }
  60.                 if( (identifiant!=null && identifiant.equals(id))
  61.                && (motdepasse!=null && motdepasse.equals(mdp)) ) //vérifier l’égalité des valeurs
  62.                           {
  63.                               out.println("Authentification correcte, bienvenue : "+identifiant);
  64.                               Client c=new Client();
  65.                               c.setIdentifiant(identifiant);
  66.                               c.setMotdepasse(motdepasse);
  67.                               getServletContext().setAttribute("client", c);
  68.                               response.sendRedirect("AuthentificationCorrecte.html");
  69.                           }
  70.                 else
  71.                 {
  72.                     out.println("Authentification incorrecte, mauvaise saisie des informations !");
  73.                     out.println("Veuillez contacter l'administrateur:"+email);
  74.                 }
  75.             }
  76.             //générer le code HTML pour le formulaire d’authentification
  77.             }
  78.  
  79.             public void doPost(HttpServletRequest request, HttpServletResponse
  80.         response)throws ServletException, IOException
  81.             {
  82.                 doGet(request, response);
  83.             }
  84.  
  85.         }
Advertisement
Add Comment
Please, Sign In to add comment