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
870 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. char[] randomString = new char[quantity];
  20. Random random = new Random();
  21. int capitalLetter;
  22. for (int i = 0; i < quantity; i++) {
  23. capitalLetter = 65 + random.nextInt(26);
  24. randomString[i] = (char) capitalLetter;
  25. }
  26. return new String(randomString);
  27. }
  28. }