Commit 4d492590 by Liv Haapala

vrauthcode for card

1 parent 44570d1b
...@@ -96,6 +96,53 @@ public class BarcodeBean implements BarcodeBeanLocal { ...@@ -96,6 +96,53 @@ public class BarcodeBean implements BarcodeBeanLocal {
return hexcode; return hexcode;
} }
public String getVrAuthCodeForCard(PrintedCard printedCard) {
StringBuilder sb = new StringBuilder();
sb.append(PRINTED_CARD_PREFIX);
if(printedCard == null)
return "";
String idStr = printedCard.getId().toString();
for (int i = 8 - idStr.length() - sb.length(); i > 0; --i) {
sb.append("0");
}
sb.append(idStr);
String code = sb.toString();
String hexcode = Integer.toHexString(Integer.parseInt(code));
String checksum = Integer.toHexString(hexcode.hashCode());
checksum = checksum.substring(checksum.length() -3);
hexcode += checksum;
//hexcode = Integer.toString(hexcode.hashCode());
logger.debug("Geneating VrAuthcode for card {} : {}", printedCard.getId(), hexcode);
return hexcode;
}
public String checkVrAuthCode(String code) {
String checksumNew = code.substring(code.length() -3);
code = code.substring(0, (code.length()-3));
String checksumOld = Integer.toHexString(code.hashCode());
checksumOld = checksumOld.substring(checksumOld.length() -3);
if(checksumNew == checksumOld) {
int decimal = Integer.decode(code);
code = Integer.toString(decimal);
String prefix = code.substring(0, 2);
int id = Integer.parseInt(code.substring(3, code.length() -1));
if(prefix == PRINTED_CARD_PREFIX && id != 0) {
PrintedCard printedCard = printedCardFacade.find(id);
if(printedCard != null)
return printedCard.getUser().getNick();
else
return "Invalid";
}
} else {
return "Invalid";
}
return "Invalid";
}
@Override @Override
public Place getPlaceFromHexcode(String hexcode) { public Place getPlaceFromHexcode(String hexcode) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!