Advertisement
Guest User

Untitled

a guest
Jul 30th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. /**
  2. * @see HttpServlet#HttpServlet()
  3. */
  4. public Loginaction() {
  5. super();
  6. // TODO Auto-generated constructor stub
  7. }
  8.  
  9. /**
  10. * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
  11. */
  12. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  13. doPost(request,response);
  14. }
  15.  
  16. /**
  17. * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
  18. */
  19. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  20. HttpSession session = request.getSession(true);
  21. String username = request.getParameter("nom");
  22. String password = request.getParameter("pass");
  23. UserDAO user = new UserDAO();
  24. boolean result = user.authentification(username, password);
  25. BaseUser user1 = user.getusername(username);
  26. if(result == true){
  27. session.setAttribute("user", user1);
  28. request.getRequestDispatcher("Liste_Projets.jsp").forward(request, response);
  29. }else{
  30. request.getRequestDispatcher("wrong_list.jsp").forward(request, response);
  31. }
  32. }
  33.  
  34. public class UserDAO extends BaseUser{
  35. public boolean authentification(String login, String mdp){
  36. BaseUser user = getusername(login);
  37. if(user!=null){
  38. if(user.getLogin().equals(login) && user.getPassword().equals(mdp))
  39. return true;
  40. else
  41. return false;
  42. }
  43. }
  44. public BaseUser getusername(String login) {
  45. Session session = HibernateUtil.currentSession();
  46. Transaction tx = null;
  47. BaseUser user = null;
  48. try {
  49. tx = session.getTransaction();
  50. tx.begin();
  51. Query query = session.createQuery("from User where LOGIN='"+login+"'");
  52. user = (BaseUser)query.uniqueResult();
  53. tx.commit();
  54. } catch (Exception e) {
  55. if (tx != null) {
  56. tx.rollback();
  57. }
  58. e.printStackTrace();
  59. } finally {
  60. HibernateUtil.closeSession();
  61. }
  62. return user;
  63. }
  64.  
  65. package suivi.base;
  66.  
  67. import java.io.Serializable;
  68.  
  69. /*
  70. * @hibernate.class
  71. * table="User"
  72. */
  73. public abstract class BaseUser implements Serializable {
  74.  
  75. private int hashCode = Integer.MIN_VALUE;
  76.  
  77. // primary key
  78. private java.lang.String _login;
  79.  
  80. // fields
  81. private java.lang.String _nomPrenom;
  82. private java.lang.String _password;
  83. private java.lang.String _login;
  84.  
  85.  
  86. // constructors
  87. public BaseUser () {
  88. initialize();
  89. }
  90.  
  91. /**
  92. * Constructor for primary key
  93. */
  94. public BaseUser (java.lang.String _login) {
  95. this.setLogin(_login);
  96. initialize();
  97. }
  98.  
  99. /**
  100.  
  101.  
  102. protected void initialize () {}
  103. /**
  104. * Return the unique identifier of this class
  105. * @hibernate.id
  106. * generator-class="vm"
  107. * column="LOGIN"
  108. */
  109. public java.lang.String getLogin () {
  110. return _login;
  111. }
  112.  
  113. /**
  114. * Set the unique identifier of this class
  115. * @param _login the new ID
  116. */
  117. public void setLogin (java.lang.String _login) {
  118. this._login = _login;
  119. this.hashCode = Integer.MIN_VALUE;
  120. }
  121.  
  122.  
  123. /**
  124. * Return the value associated with the column: NOM_PRENOM
  125. */
  126. public java.lang.String getNomPrenom () {
  127. return _nomPrenom;
  128. }
  129.  
  130. /**
  131. * Set the value related to the column: NOM_PRENOM
  132. * @param _nomPrenom the NOM_PRENOM value
  133. */
  134. public void setNomPrenom (java.lang.String _nomPrenom) {
  135. this._nomPrenom = _nomPrenom;
  136. }
  137.  
  138.  
  139. /**
  140. * Return the value associated with the column: PASSWORD
  141. */
  142. public java.lang.String getPassword () {
  143. return _password;
  144. }
  145.  
  146. /**
  147. * Set the value related to the column: PASSWORD
  148. * @param _password the PASSWORD value
  149. */
  150. public void setPassword (java.lang.String _password) {
  151. this._password = _password;
  152. }
  153.  
  154.  
  155. public String toString () {
  156. return super.toString();
  157. }
  158.  
  159. <script type="text/javascript">
  160. function Annuler(){
  161. document.login.reset();
  162. }
  163. function valider()
  164. {
  165. var ok = true;
  166. if (document.getElementById("nom").value.length<1)
  167. {
  168. ok = false;
  169. document.getElementById("erreurLogin").innerHTML="*Obligatoire";
  170. }
  171.  
  172. var x = document.getElementById("pass").value;
  173. if(x == "")
  174. {
  175. ok = false;
  176. document.getElementById("erreurLogin1").innerHTML="*Obligatoire";
  177. }
  178. if(ok)
  179. {
  180.  
  181. document.login.submit()
  182.  
  183. }
  184.  
  185. }
  186. </script>
  187. ...//code
  188. <body>
  189. <form name="login" method="Post" action="Loginaction">
  190. <tr height="40px" valign="bottom">
  191. <td width="150px"> </td>
  192. <td class="StyleLabel">Identifiant: </td>
  193. <td width="1px"></td>
  194. <td colspan="2" ><input class="input" type="text" size="24" maxlength="20" name="nom" id="nom"></td>
  195. <td><label class="asterix" id="erreurLogin"></label></td>
  196. </tr>
  197.  
  198. <tr height="40px" valign="bottom">
  199. <td width="150px"></td>
  200. <td width="100px" class="StyleLabel" >Mot de passe: </td>
  201. <td width="1px"></td>
  202. <td colspan="2" > <input class="input" type="password" size="24" autocomplete="off" maxlength="20" name="pass" id="pass"> </td>
  203. <td ><label class="asterix" id="erreurLogin1"></label></td>
  204. </tr>
  205.  
  206. <tr height="40px" >
  207. <td> </td>
  208. <td colspan="3" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/btnValid.gif" name="valid" value="valid" type="submit" onclick="valider();"/></td>
  209. <td colspan="3" align="center">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="images/btnAnnul.gif" onclick="Annuler();"/></td>
  210. </tr>
  211. </table>
  212.  
  213. public boolean authentification(String login, String mdp){
  214. BaseUser user = getusername(login);
  215. if(user!=null )
  216. {
  217. if(user.getLogin().equals(login) && user.getPassword().equals(mdp))
  218. return true;
  219. else
  220. return false;
  221. }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement