javascript - 登录表单的输入验证是否过大?开销 + "too much javascript"问题

标签 javascript jquery authentication validation

在为我的注册表创建输入验证时,我想到了在我的登录表单上进行输入验证。我的登录表单需要电子邮件和密码。在 blur 上验证(并且仅当先前输入无效时才在 keyup 上验证)是否在电子邮件文本字段中输入的是电子邮件地址,并且密码是否具有最小长度(注册需要密码至少为 6 个字符)?

我已经编写了服务器端逻辑来处理登录,因此不执行输入验证将重定向到“有效输入但不正确”或“电子邮件不在系统中”错误页面。*

知道这一点,会不会太过分了?让用户在每次登录时都能直观地知道他们输入的数据格式正确是否很好?

*(由于我们讨论的是登录主题,非常感谢您就我的另一个问题提供意见。

目前,我的系统对不正确的电子邮件/密码组合的通知与对不在系统中的电子邮件的通知不同。我注意到许多网站对两者都有相同的消息(例如:“用户名或密码可能不正确”),但很多网站却没有。

这可能是因为他们不希望人们能够嗅出用户。然而,嗅探也可以在注册期间完成(因为如果用户名/电子邮件已经在系统中,所有系统都会通知用户)。我应该更改我的系统以允许歧义,还是就这样好了?)

最佳答案

Would it be overkill to validate on blur (and on keyup only if the previous input was invalid) whether what is entered in the e-mail text field is an e-mail address, and that the password is of the minimum length (registration requires that the password be at least 6 characters)?

不,验证模糊并不过分。在 keyup 上验证就太过分了。作为用户,我个人认为这很烦人。

I already coded the server-side logic to handle login, so not implementing the input validation would redirect to either the "valid input but incorrect" or "e-mail not in system" error pages.*

我会建议再次使用此类错误页面,而是再次重定向到登录表单,并显示错误报告说某某无效。错误消息应该用于数据库中不匹配的有效数据

Currently, my system has a different notification for an incorrect e-mail/password combo than it does for an e-mail that's not in the system. I notice many sites have the same message for both (something like: "user-name or password may be incorrect"), and many don't.

许多系统可能比您预期的要复杂。某些系统无法检测用户是否不存在,因为它们将用户/密码视为单个实体。如果您以不同的方式对待他们,请随时向用户提供更多信息。

Should I change my system to allow for ambiguity, or is it fine as is?)

我建议您给错误消息“用户名不正确”和“用户名或密码不正确”。用户不需要被告知该用户名在您的数据库中不存在,它只需要知道他输入的用户名有误。

更不用说等待服务器往返的延迟明显高于本地 javascript 反馈。如果您使用 node.js 之类的东西,您甚至可以在一个地方进行验证,而无需维护它的两个副本。

关于javascript - 登录表单的输入验证是否过大?开销 + "too much javascript"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5687646/

相关文章:

javascript - 动态加载的内容点击事件未触发

ruby-on-rails - Devise token auth 无法验证 CSRF token 的真实性

javascript - 如何使用 Angular 对所有数组值求和

javascript - 如何设置自动启动brightcove视频?

javascript - 当我不想让一个函数再次运行时,如何停止它? (jquery)

ruby-on-rails - 如何根据登录方式将超时的用户重定向到不同的页面?

authentication - couchdb 读取认证

javascript - 确定网页是否适用于移动设备的最佳方法是什么?

javascript - 触摸友好的下拉菜单

javascript - 处理选择标记之间的交集