From b1ec2f59af2289a77657726ee86c2d64f3571813 Mon Sep 17 00:00:00 2001 From: Suchakra Sharma Date: Tue, 9 Mar 2021 09:46:14 -0800 Subject: [PATCH] Add a weak hash usage --- .../shiftleft/controller/CustomerController.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/shiftleft/controller/CustomerController.java b/src/main/java/io/shiftleft/controller/CustomerController.java index 40e1c4917..4a00780f6 100644 --- a/src/main/java/io/shiftleft/controller/CustomerController.java +++ b/src/main/java/io/shiftleft/controller/CustomerController.java @@ -378,10 +378,20 @@ public void updateCustomer(@RequestBody Customer customer, @PathVariable("custom * the customer id */ @RequestMapping(value = "/customers/{customerId}", method = RequestMethod.DELETE) - public void removeCustomer(@PathVariable("customerId") Long customerId, HttpServletResponse httpResponse) { + public void removeCustomer(@PathVariable("customerId") Long customerId, HttpServletResponse httpResponse) throws NoSuchAlgorithmException { + MessageDigest md; + try { + md = MessageDigest.getInstance("MD5"); + } + catch (Exception e) { + throw new NoSuchAlgorithmException(e); + } - if (customerRepository.exists(customerId)) { - customerRepository.delete(customerId); + md.update(customerId.toString().getBytes()); + byte[] digest = md.digest(); + String newCustomerId = new String(digest); + if (customerRepository.exists(Long.parseLong(newCustomerId))) { + customerRepository.delete(Long.parseLong(newCustomerId)); } httpResponse.setStatus(HttpStatus.NO_CONTENT.value());