JAVA   59
boolean Verify
Guest on 14th August 2022 06:34:46 AM


  1. // The following code will authenticate the monitor
  2. // passwd is the user's password, chksum is the string returned by the monitor
  3. // when sending the "PARTICIPANT_PASSWORD_CHECKSUM" directive
  4.  
  5. public boolean Verify(String passwd, String chksum) {
  6.    try {
  7.       MessageDigest md = MessageDigest.getInstance("SHA");
  8.       passwd = passwd.toUpperCase();
  9.       byte[] byteArr = passwd.getBytes();
  10.       md.update(byteArr);
  11.       // *** The following two lines are deprecated - use Coleman Kane's ***
  12.       // *** modification following them  ***
  13.       // BigInteger big = new BigInteger(md.digest());
  14.       // if ((big.abs().toString(16).equals(chksum.trim()))) return true;
  15.       BigInteger big = new BigInteger(1, md.digest());
  16.       if ((big.toString(16).equals(chksum.trim()))) return true;
  17.       else return false;
  18.    } catch (Exception e) {       
  19.       return false;
  20.    }
  21. }

Raw Paste

Login or Register to edit or fork this paste. It's free.