url/user/unique_username VS /user/id/possible_duplicate,我应该选择什么?
每当我考虑建立一个内部注册多个用户的新网站时,我总是问自己使用唯一的用户名或重复的用户名是否更好。后者的一个示例是 StackOverflow 站点(因为它使用唯一的用户 ID 而不是唯一的用户名)。
我总是选择前一个选择,但我讨厌它,因为很多时候你就是不能使用你最喜欢的用户名。
我应该选择什么?是否有一些好的建议可以帮助做出决定?
Every time I think to build a new site with multiple users registered inside I always ask myself if it's better with unique usernames or duplicated usernames. An example of the latter is the Stack Overflow site (because it works with the unique user id instead of a unique username).
I always choose the former choice, but I hate it because many times you just can't use your favourite username.
What should I choose? Does some good advice exist for helping to decide?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为使用电子邮件地址作为登录的用户 ID 并拥有允许用户选择非唯一昵称的配置文件是最好的方法。电子邮件地址更难忘记,而且不太可能(实际上不可能 - 除了试图开设多个帐户的用户)使您陷入名称冲突。无论如何,您还希望将真实的电子邮件地址作为您的用户配置文件的一部分,因为您希望能够联系您的会员,并且您最终需要向许多/大多数用户发送密码重置电子邮件。
话虽如此,我会为用户配置文件使用内部唯一 ID,例如 IDENTITY 整数或 GUID。这是因为电子邮件地址不是一成不变的。您希望成员能够在不破坏您的外键的情况下更改他们的电子邮件。尽管如此,电子邮件应该是您的用户/成员表中的候选键。
I think using an e-mail address as the user ID for logging in and having a profile which allows the user to pick a non-unique nickname is the best approach. The e-mail address is harder to forget and very unlikely (impossible really - except for users trying to open multiple accounts) to get you into name collisions. You also want to have real e-mail addresses as part of your user profiles anyway because you want to be able to reach your members and you'll eventually need to send a password reset e-mail to many/most users anyway.
Having said that, I would use an internal unique ID for the user profile, such as an IDENTITY integer or a GUID. This is because e-mail address is not immutable. You want members to be able to change their e-mails without disrupting your foreign keys. Still, e-mail should be a candidate key in your user/member table.
堆栈溢出允许重复名称,但不允许重复用户。 (不是您所说的方式。)每个 StackOverflow 用户都有一个唯一的 ID 号,包括您的(185921)。每个 StackOverflow 用户还有一个可能不唯一的“名称”。
StackOverflow 允许每个用户选择自己的“名称”,但 StackOverflow 代码不使用它。堆栈溢出代码使用唯一的 ID 号。
Stack Overflow allows duplicate names, but not duplicate users. (Not the way you seem to be talking about.) Each Stack Overflow user has a unique id number, including yours (it's 185921). Each Stack Overflow user also has a "name" that might not be unique.
Stack Overflow lets each user pick their own "name", but Stack Overflow code doesn't use it. Stack Overflow code uses the unique id number.