Compare commits
12 Commits
75343bb92d
...
fac4982746
| Author | SHA1 | Date |
|---|---|---|
|
|
fac4982746 | 1 week ago |
|
|
ab54446925 | 1 week ago |
|
|
74398ff98b | 1 week ago |
|
|
84b040ec4d | 1 week ago |
|
|
5aa492b4e9 | 1 week ago |
|
|
9003cdc454 | 1 week ago |
|
|
67dee22aaa | 1 week ago |
|
|
aa04fd7c4b | 1 week ago |
|
|
c32492aa8f | 1 week ago |
|
|
537954d30f | 1 week ago |
|
|
febce89baf | 1 week ago |
|
|
0653e5887b | 1 week ago |
19 changed files with 183 additions and 171 deletions
@ -0,0 +1,27 @@ |
|||||
|
package com.techsor.datacenter.business.service.captcha; |
||||
|
|
||||
|
import cn.hutool.captcha.generator.CodeGenerator; |
||||
|
|
||||
|
public class HutoolCaptchaGenerator implements CodeGenerator { |
||||
|
|
||||
|
private int length = 4; |
||||
|
private static final String chars = "23456789abcdefghkmnpqrstuvwxyzABCDEFGHKMNPRSTUVWXYZ"; |
||||
|
|
||||
|
@Override |
||||
|
public String generate() { |
||||
|
StringBuilder sb = new StringBuilder(length); |
||||
|
for (int i = 0; i < length; i++) { |
||||
|
int idx = (int) (Math.random() * chars.length()); |
||||
|
sb.append(chars.charAt(idx)); |
||||
|
} |
||||
|
return sb.toString(); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public boolean verify(String code, String userInput) { |
||||
|
if (code == null || userInput == null) { |
||||
|
return false; |
||||
|
} |
||||
|
return code.equalsIgnoreCase(userInput); |
||||
|
} |
||||
|
} |
||||
@ -1,36 +0,0 @@ |
|||||
package com.techsor.datacenter.business.service.captcha; |
|
||||
|
|
||||
import java.util.Properties; |
|
||||
|
|
||||
import org.springframework.context.annotation.Bean; |
|
||||
import org.springframework.context.annotation.Configuration; |
|
||||
|
|
||||
import com.google.code.kaptcha.impl.DefaultKaptcha; |
|
||||
import com.google.code.kaptcha.util.Config; |
|
||||
|
|
||||
@Configuration |
|
||||
public class KaptchaConfig { |
|
||||
@Bean |
|
||||
public DefaultKaptcha producer(){ |
|
||||
|
|
||||
DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); |
|
||||
Properties properties = new Properties(); |
|
||||
properties.setProperty("kaptcha.border", "no"); |
|
||||
properties.setProperty("kaptcha.border.color", "105,179,90"); |
|
||||
properties.setProperty("kaptcha.textproducer.font.color", "black"); |
|
||||
properties.setProperty("kaptcha.image.width", "110"); |
|
||||
properties.setProperty("kaptcha.image.height", "40"); |
|
||||
properties.setProperty("kaptcha.textproducer.char.string","23456789abcdefghkmnpqrstuvwxyzABCDEFGHKMNPRSTUVWXYZ"); |
|
||||
properties.setProperty("kaptcha.textproducer.font.size", "30"); |
|
||||
properties.setProperty("kaptcha.textproducer.char.space","3"); |
|
||||
properties.setProperty("kaptcha.session.key", "code"); |
|
||||
properties.setProperty("kaptcha.textproducer.char.length", "4"); |
|
||||
properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑"); |
|
||||
// properties.setProperty("kaptcha.obscurificator.impl","com.xxx");可以重写实现类
|
|
||||
properties.setProperty("kaptcha.noise.impl","com.google.code.kaptcha.impl.NoNoise"); |
|
||||
Config config = new Config(properties); |
|
||||
defaultKaptcha.setConfig(config); |
|
||||
|
|
||||
return defaultKaptcha; |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue