Skip to content

Commit

Permalink
验证码限流
Browse files Browse the repository at this point in the history
  • Loading branch information
jobmission committed Aug 11, 2018
1 parent bc3fe66 commit dd11ae0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
Expand Down Expand Up @@ -112,6 +107,12 @@
<version>0.5.0</version>
</dependency>

<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.revengemission.sso.oauth2.server.controller;

import com.google.common.util.concurrent.RateLimiter;
import com.revengemission.sso.oauth2.server.domain.GlobalConstant;
import org.patchca.color.SingleColorFactory;
import org.patchca.filter.predefined.CurvesRippleFilterFactory;
Expand All @@ -19,6 +20,11 @@

@Controller
public class VerificationCodeController {


//每秒只发出100个令牌
RateLimiter rateLimiter = RateLimiter.create(100.0);

/**
* 验证码
*
Expand All @@ -32,6 +38,10 @@ public void captcha(HttpServletRequest request,
@RequestParam(value = "w", defaultValue = "160") int width,
@RequestParam(value = "h", defaultValue = "40") int height,
@RequestParam(value = "length", defaultValue = "4") int length) throws IOException {

if (!rateLimiter.tryAcquire()) {
return;
}
if (length < 4) {
length = 4;
}
Expand Down

0 comments on commit dd11ae0

Please sign in to comment.