SmartKaptchaConfig.java 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package net.lab1024.smartadmin.config;
  2. import net.lab1024.smartadmin.common.kaptcha.KaptchaNoise;
  3. import net.lab1024.smartadmin.common.kaptcha.KaptchaWordRenderer;
  4. import com.google.code.kaptcha.impl.DefaultKaptcha;
  5. import com.google.code.kaptcha.util.Config;
  6. import org.springframework.context.annotation.Bean;
  7. import org.springframework.context.annotation.Configuration;
  8. import java.util.Properties;
  9. /**
  10. * [ 验证码配置 ]
  11. *
  12. * @author yandanyang
  13. * @version 1.0
  14. * @company 1024lab.net
  15. * @copyright (c) 2018 1024lab.netInc. All rights reserved.
  16. * @date 2019/7/4 0004 上午 9:40
  17. * @since JDK1.8
  18. */
  19. @Configuration
  20. public class SmartKaptchaConfig {
  21. @Bean
  22. public DefaultKaptcha getDefaultKaptcha(){
  23. DefaultKaptcha defaultKaptcha=new DefaultKaptcha();
  24. Properties properties=new Properties();
  25. properties.setProperty("kaptcha.border", "no");
  26. properties.setProperty("kaptcha.border.color", "34,114,200");
  27. properties.setProperty("kaptcha.image.width", "125");
  28. properties.setProperty("kaptcha.image.height", "45");
  29. properties.setProperty("kaptcha.textproducer.char.string", "0123456789");
  30. properties.setProperty("kaptcha.textproducer.char.length", "4");
  31. properties.setProperty("kaptcha.textproducer.font.names", "Arial,Arial Narrow,Serif,Helvetica,Tahoma,Times New Roman,Verdana");
  32. properties.setProperty("kaptcha.textproducer.font.size", "38");
  33. properties.setProperty("kaptcha.background.clear.from", "white");
  34. properties.setProperty("kaptcha.background.clear.to", "white");
  35. properties.setProperty("kaptcha.word.impl", KaptchaWordRenderer.class.getName());
  36. properties.setProperty("kaptcha.noise.impl", KaptchaNoise.class.getName());
  37. Config config=new Config(properties);
  38. defaultKaptcha.setConfig(config);
  39. return defaultKaptcha;
  40. }
  41. }