Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. /**
  2. * 检查注册码
  3. * @return
  4. */
  5. public Boolean checkSN() {
  6. String username = et_username.getText().toString();
  7. String password = et_password.getText().toString();
  8. if (username.length() == 0) {
  9. return false;
  10. }
  11. if (password.length() != 16) {
  12. return false;
  13. }
  14. try {
  15. MessageDigest messageDigest = MessageDigest.getInstance("MD5");
  16. messageDigest.digest();
  17. messageDigest.update(username.getBytes());
  18. byte[] bytes = messageDigest.digest();
  19. String hexstr = toHexString(bytes, "");
  20. StringBuilder stringBuilder = new StringBuilder();
  21. for (int i = 0; i < hexstr.length(); i += 2){
  22. stringBuilder.append(hexstr.charAt(i));
  23. }
  24. String userSN = stringBuilder.toString();
  25. if (!userSN.equalsIgnoreCase(password)) {
  26. return false;
  27. }
  28.  
  29. } catch (NoSuchAlgorithmException e) {
  30. e.printStackTrace();
  31. return false;
  32. }
  33. return true;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement