A self hosted chat application with end-to-end encrypted messaging.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
929 B

  1. package org.ros.chatto.captcha;
  2. import java.awt.image.BufferedImage;
  3. import java.util.Random;
  4. public class SimpleCaptchaBehavior implements CaptchaBehaviour {
  5. @Override
  6. public BufferedImage generateCaptcha() {
  7. SimpleCaptcha simpleCaptcha = new SimpleCaptcha();
  8. return simpleCaptcha.getImagePng();
  9. }
  10. @Override
  11. public BufferedImage generateCaptcha(String captchaText) {
  12. SimpleCaptcha simpleCaptcha = new SimpleCaptcha(captchaText);
  13. return simpleCaptcha.getImagePng();
  14. }
  15. public String getRandomChars() {
  16. return getRandomChars(8);
  17. }
  18. public String getRandomChars(int quantity)
  19. {
  20. char[] randomString = new char[quantity];
  21. Random random = new Random();
  22. int capitalLetter;
  23. for (int i = 0; i < quantity; i++) {
  24. capitalLetter = 65 + random.nextInt(26);
  25. randomString[i] = (char) capitalLetter;
  26. }
  27. return new String(randomString);
  28. }
  29. }