用户名作为数据库 ID
我正在创建一个简单的网络应用程序。
即使在应用程序底层,通过用户名来识别用户是否是错误的?
例如,假设我有一个身份验证令牌表,其中包含三列:令牌、用户 ID、expDate。 将用户名放在userID栏中会不会出错?
我是否需要担心每个人都知道我的数据库中的用户 ID?
I am creating a simple web application.
Is it wrong to identify user by it's user name even in the application low level?
For example, say I have a authentication token table that has three columns: token, userID, expDate.
Will it be wrong to put the user username in userID column?
Do I have to worry about the fact that everybody knows the user ID in my DB?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,我不认为这有什么特别的问题。我在非常大的站点的实践中看到了这一点 - 只需确保您对该值有唯一的约束和索引(更好,使其成为主键)。另外,请考虑使用用户名作为 ID 意味着您不能让用户稍后在不破坏现有链接的情况下更改其用户名(例如,如果您的用户在外部共享其用户页面)。
No, I don't think there's anything wrong with that particularly. I've seen that in practice at very big sites - just make sure that you have a unique constraint and index for that value (better, make it the primary key). Also, consider that using the username as their ID means you can't let the user change their username later without breaking existing links (say, if your user shares their user page externally).
我不确定,但使用字符串而不是数字可能会产生一些开销。
此外,如果用户的用户名发生更改,更新其他数据库表可能会很麻烦。
I'm not sure, but there might be some overhead from using a string instead of a number.
Also it could be a hassle to update other database tables if a user's username ever changes.