Guest User

Untitled

a guest
Jun 8th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.22 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package beanUtenti;
  6.  
  7. import java.sql.ResultSet;
  8. import java.sql.SQLException;
  9. import java.util.logging.Level;
  10. import java.util.logging.Logger;
  11. import javax.faces.context.FacesContext;
  12. import tools.GestoreDB;
  13. import tools.Utils;
  14.  
  15. /**
  16. *
  17. * @author dama
  18. */
  19. public class modificaEmailPass {
  20.  
  21. UtenteLoggato utenteLoggato = Utils.getCurrentUtenteLoggato(FacesContext.getCurrentInstance());
  22. private String username="paolo.marino";
  23. private String oldPassword; //="Paolo1";
  24. private String newPassword;
  25. private String newPasswordConfirm;
  26. private GestoreDB gestoreDB;
  27.  
  28. //TODO: invece che ritornare gli errori gestirli con il logging
  29. public String modifica(){
  30. String command;
  31. ResultSet result;
  32.  
  33. if(getOldPassword() == null){
  34. System.out.println("oldPasssword NULL");
  35. return "oldPasssword NULL";
  36. }
  37. if(getNewPassword() == null || getNewPasswordConfirm() == null ){
  38. System.out.println("newPassword NULL");
  39. return "newPassword NULL";
  40. }
  41. if(!newPassword.equals(newPasswordConfirm)){
  42. System.out.println("newPasswords are not the same");
  43. return "newPasswords are not the same";
  44. }else{
  45. command="SELECT COUNT(*) FROM utenti WHERE username='"+username+"' AND password='"+getOldPassword()+"'";
  46.  
  47. try {
  48. gestoreDB=GestoreDB.getInstance();
  49. result=gestoreDB.executeQuery(command);
  50.  
  51. if( result.getInt("COUNT(*)") == 0){
  52. System.out.println("wrong oldPassword");
  53. }
  54. command = "UPDATE utenti SET password='" + getNewPassword() + "' WHERE username='" + username + "'";
  55. gestoreDB.executeStatement(command);
  56. System.out.println("Password Updated");
  57. System.out.println("Query="+command);
  58.  
  59. } catch (SQLException ex) {
  60. System.out.println("SQLException thrown");
  61. throw new RuntimeException(ex);
  62. }
  63.  
  64. return "";
  65. }
  66. }
  67.  
  68. /**
  69. * @return the oldPassword
  70. */
  71. public String getOldPassword() {
  72. return oldPassword;
  73. }
  74.  
  75. /**
  76. * @return the newPassword
  77. */
  78. public String getNewPassword() {
  79. return newPassword;
  80. }
  81.  
  82. /**
  83. * @return the newPasswordConfirm
  84. */
  85. public String getNewPasswordConfirm() {
  86. return newPasswordConfirm;
  87. }
  88.  
  89. /**
  90. * @param oldPassword the oldPassword to set
  91. */
  92. public void setOldPassword(String oldPassword) {
  93. this.oldPassword = oldPassword;
  94. }
  95.  
  96. /**
  97. * @param newPassword the newPassword to set
  98. */
  99. public void setNewPassword(String newPassword) {
  100. this.newPassword = newPassword;
  101. }
  102.  
  103. /**
  104. * @param newPasswordConfirm the newPasswordConfirm to set
  105. */
  106. public void setNewPasswordConfirm(String newPasswordConfirm) {
  107. this.newPasswordConfirm = newPasswordConfirm;
  108. }
  109.  
  110. }
Add Comment
Please, Sign In to add comment