0

今天我正在寻找一种方法来使我们的服务器更强大,以抵御一种非常特殊的 DOS 攻击。

我们使用强度为 12 的 BCrypt 来存储用户密码。在我们的环境中验证密码可能需要长达 500 毫秒。

登录时的用户可以接受。我认为有人可能会向我们的服务器发送带有无效密码的登录请求,以使其承受重负载。

首先我认为这个问题只能发生在现有用户身上,但是在调试过程中我在 DaoAuthenticationProvider 中发现了这段代码:

    } catch (UsernameNotFoundException notFound) {
        if(authentication.getCredentials() != null) {
            String presentedPassword = authentication.getCredentials().toString();
            passwordEncoder.isPasswordValid(userNotFoundEncodedPassword, presentedPassword, null);
        }
        throw notFound;

如果发生 UsernameNotFoundException,它会根据 userNotFoundEncodedPassword 检查提供的密码!
另外这里系统需要同样的计算时间,导致userNotFoundEncodedPassword的强度也是12。
在哪里设置?
我怎样才能避免这种计算?
我必须编写自己的 AuthenticationProvider 吗?

4

0 回答 0