Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- package beanUtenti;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.faces.context.FacesContext;
- import tools.GestoreDB;
- import tools.Utils;
- /**
- *
- * @author dama
- */
- public class modificaEmailPass {
- UtenteLoggato utenteLoggato = Utils.getCurrentUtenteLoggato(FacesContext.getCurrentInstance());
- private String username="paolo.marino";
- private String oldPassword; //="Paolo1";
- private String newPassword;
- private String newPasswordConfirm;
- private GestoreDB gestoreDB;
- //TODO: invece che ritornare gli errori gestirli con il logging
- public String modifica(){
- String command;
- ResultSet result;
- if(getOldPassword() == null){
- System.out.println("oldPasssword NULL");
- return "oldPasssword NULL";
- }
- if(getNewPassword() == null || getNewPasswordConfirm() == null ){
- System.out.println("newPassword NULL");
- return "newPassword NULL";
- }
- if(!newPassword.equals(newPasswordConfirm)){
- System.out.println("newPasswords are not the same");
- return "newPasswords are not the same";
- }else{
- command="SELECT COUNT(*) FROM utenti WHERE username='"+username+"' AND password='"+getOldPassword()+"'";
- try {
- gestoreDB=GestoreDB.getInstance();
- result=gestoreDB.executeQuery(command);
- if( result.getInt("COUNT(*)") == 0){
- System.out.println("wrong oldPassword");
- }
- command = "UPDATE utenti SET password='" + getNewPassword() + "' WHERE username='" + username + "'";
- gestoreDB.executeStatement(command);
- System.out.println("Password Updated");
- System.out.println("Query="+command);
- } catch (SQLException ex) {
- System.out.println("SQLException thrown");
- throw new RuntimeException(ex);
- }
- return "";
- }
- }
- /**
- * @return the oldPassword
- */
- public String getOldPassword() {
- return oldPassword;
- }
- /**
- * @return the newPassword
- */
- public String getNewPassword() {
- return newPassword;
- }
- /**
- * @return the newPasswordConfirm
- */
- public String getNewPasswordConfirm() {
- return newPasswordConfirm;
- }
- /**
- * @param oldPassword the oldPassword to set
- */
- public void setOldPassword(String oldPassword) {
- this.oldPassword = oldPassword;
- }
- /**
- * @param newPassword the newPassword to set
- */
- public void setNewPassword(String newPassword) {
- this.newPassword = newPassword;
- }
- /**
- * @param newPasswordConfirm the newPasswordConfirm to set
- */
- public void setNewPasswordConfirm(String newPasswordConfirm) {
- this.newPasswordConfirm = newPasswordConfirm;
- }
- }
Add Comment
Please, Sign In to add comment