|
@@ -30,8 +30,12 @@ public class ValidateCodeServlet extends HttpServlet {
|
|
|
|
|
|
|
|
public static final String VALIDATE_CODE = "validateCode";
|
|
public static final String VALIDATE_CODE = "validateCode";
|
|
|
|
|
|
|
|
- private int w = 70;
|
|
|
|
|
- private int h = 26;
|
|
|
|
|
|
|
+ private int w = 95;
|
|
|
|
|
+ private int h = 40;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 干扰线数量
|
|
|
|
|
+ */
|
|
|
|
|
+ private int lineSize = 10;
|
|
|
|
|
|
|
|
public ValidateCodeServlet() {
|
|
public ValidateCodeServlet() {
|
|
|
super();
|
|
super();
|
|
@@ -118,7 +122,7 @@ public class ValidateCodeServlet extends HttpServlet {
|
|
|
g.setColor(getRandColor(220,250));
|
|
g.setColor(getRandColor(220,250));
|
|
|
g.fillRect(0, 0, w, h);
|
|
g.fillRect(0, 0, w, h);
|
|
|
// 加入干扰线条
|
|
// 加入干扰线条
|
|
|
- for (int i = 0; i < 8; i++) {
|
|
|
|
|
|
|
+ for (int i = 0; i < lineSize; i++) {
|
|
|
g.setColor(getRandColor(40,150));
|
|
g.setColor(getRandColor(40,150));
|
|
|
Random random = new Random();
|
|
Random random = new Random();
|
|
|
int x = random.nextInt(w);
|
|
int x = random.nextInt(w);
|
|
@@ -138,8 +142,8 @@ public class ValidateCodeServlet extends HttpServlet {
|
|
|
StringBuilder s = new StringBuilder();
|
|
StringBuilder s = new StringBuilder();
|
|
|
for (int i = 0; i < 4; i++) {
|
|
for (int i = 0; i < 4; i++) {
|
|
|
String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10));
|
|
String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10));
|
|
|
- g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100)));
|
|
|
|
|
- g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)],Font.BOLD,26));
|
|
|
|
|
|
|
+ g.setColor(new Color(random.nextInt(101), random.nextInt(111), random.nextInt(121)));
|
|
|
|
|
+ g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)],Font.BOLD,24));
|
|
|
g.drawString(r, 15 * i + 5, 19 + random.nextInt(8));
|
|
g.drawString(r, 15 * i + 5, 19 + random.nextInt(8));
|
|
|
// g.drawString(r, i*w/4, h-5);
|
|
// g.drawString(r, i*w/4, h-5);
|
|
|
s.append(r);
|
|
s.append(r);
|