diff --git a/src/java/com/test/forms/NouveauPompForm.java b/src/java/com/test/forms/NouveauPompForm.java index db4d698..9b57715 100644 --- a/src/java/com/test/forms/NouveauPompForm.java +++ b/src/java/com/test/forms/NouveauPompForm.java @@ -46,7 +46,7 @@ public class NouveauPompForm { if (erreur > 0) return -1; // Creation d'un objet de type Client avec les données transmises -// String mdpChiffre = MD5.encode(request.getParameter("ztMDP")); + String mdpChiffre = MD5.encode(request.getParameter("ztMDP")); Pompier unPompier = new Pompier(request.getParameter("id"), request.getParameter("idCaserne"), request.getParameter("ztNom"), diff --git a/src/java/util/MD5.java b/src/java/util/MD5.java new file mode 100644 index 0000000..cccd368 --- /dev/null +++ b/src/java/util/MD5.java @@ -0,0 +1,36 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package util; + +/** + * + * @author sio + */ + +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.logging.Level; +import java.util.logging.Logger; + +public abstract class MD5 { + + public static String encode(String uneChaine){ + MessageDigest md = null; + try { + md = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException ex) { + throw new IllegalArgumentException(ex); + } + md.update(uneChaine.getBytes()); + byte[] digest = md.digest(); + //myHash = DatatypeConverter.printHexBinary(digest).toLowerCase(); + StringBuilder sb = new StringBuilder(); + for (byte b : digest) { + sb.append(String.format("%02x", b)); + } + return sb.toString(); + } +}