如何安全地检查用户名是否已被占用?

发布于 2024-09-03 09:51:40 字数 116 浏览 5 评论 0原文

我有一个可以创建新用户的表单。我想添加一些 AJAX 来检查用户名是否被占用,一旦输入字段失去焦点。 我不太确定如何解决这个问题,因为这可能为暴力攻击铺平道路,因为您可以检查任何用户名并查看它是否存在。 有什么建议吗?

I have a form where someone can create a new user. I'd like to add some AJAX to check if a username is taken, as soon as the input field loses focus.
I'm not really sure how to go about this, as this could pave the way to bruteforce attack, since you could check for any username and see whether or not it exists.
Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

风流物 2024-09-10 09:51:40

也许最好的选择是在服务器端脚本中将允许用户在 30 分钟时间段内进行的尝试次数(基于会话或 IP)限制为合理的限制(即 10 次)。

另一种选择是在页面上放置验证码,以确保用户是人类而不是暴力程序。

Probably the best option is to limit, in the server-side script, the number of attempts a user is allowed to make (based on either session, or IP) to a sensible limit (ie. 10) within a 30 minute time period.

Another option would be to put a captcha on the page to ensure that the user is a human and not a bruteforcing program.

君勿笑 2024-09-10 09:51:40

为什么不

  1. 限制新用户可以进行的尝试次数(例如,在一分钟内只允许“n”)
  2. 提供一种机制来根据用户的输入建议可用的用户名,从而减少用户通常进行的有效尝试次数

Why not

  1. throttle the number of attempts a new user can make (e.g. only allow 'n' in a minute)
  2. provide a mechanism to suggest available usernames based on the user's input, thus reducing the number of valid attempts a user would normally make
乖乖哒 2024-09-10 09:51:40

您可以等到表单提交后进行检查,而不是在输入字段失去焦点时进行提示。如果用户名已被使用,一个可靠的解决方案是建议备用用户名。

Instead of prompting when the input field loses focus, you can wait until after the form is submitted to check. If the username is already taken, a robust solution is to suggest alternative user names.

掩饰不了的爱 2024-09-10 09:51:40

如果您是论坛,则用户名不是私人的。只需使用服务器逻辑来限制每分钟的调用次数。如果你是一家银行,那就另当别论了;但在这种情况下,您可以将用户名分配给银行帐户。

if you're a forum, usernames aren't private. just use server logic to limit the number of calls per minute. if you're a bank, different story; but in that case, you can assign usernames to bank accounts.

拥抱没勇气 2024-09-10 09:51:40

我从来没有这样做过,所以只是一个想法。生成一些随表单一起传输的唯一ID(例如uuid)。当您检查用户名时,请包含(并检查)此唯一 ID。当然,这需要一些服务器端的参与,但至少您无法在不渲染表单的情况下直接调用此函数。

注意:为了提高安全性,您需要在每次用户检查值时更新表单唯一 ID。

I've never done this, so just an idea. Generate some unique ID (e.g. uuid) transmitted along with form. When you check for the username include (and check for) this unique ID. Of course, this need some server side involvment, but at least you wouldn't be able directly call this function without rendering the form.

Note: For more security, you would need to update the forms unique ID everytime the user checks for a value.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文