/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package Metier; import Physique.BibliothecaireServiceJDBC; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.logging.Level; import java.util.logging.Logger; public class BibliothecaireServiceImpl implements BibliothecaireService { BibliothecaireServiceJDBC bibliothecaireServiceJDBC = Physique.PhysiqueFactory.getBibliothecaireServiceJDBC(); protected BibliothecaireServiceImpl(){ } @Override public ArrayList<Bibliothecaire> getAll() { return bibliothecaireServiceJDBC.getAll(); } @Override public void add(Bibliothecaire b) { if (b != null) { hasherMdp(b); bibliothecaireServiceJDBC.add(b); } } public void hasherMdp(Bibliothecaire b) { try { byte[] hash = MessageDigest.getInstance("MD5").digest(b.getMdp().getBytes()); StringBuilder hashString = new StringBuilder(); for (int i = 0; i < hash.length; i++) { String hex = Integer.toHexString(hash[i]); if (hex.length() == 1) { hashString.append('0'); hashString.append(hex.charAt(hex.length() - 1)); } else { hashString.append(hex.substring(hex.length() - 2)); } } b.setMdp(hashString.toString()); } catch (NoSuchAlgorithmException ex) { Logger.getLogger(BibliothecaireServiceImpl.class.getName()).log(Level.SEVERE, null, ex); } } @Override public void remove(Bibliothecaire b) { if (b != null) { bibliothecaireServiceJDBC.remove(b); } } @Override public void update(Bibliothecaire b) { if (b != null) { bibliothecaireServiceJDBC.remove(b); } } }