TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Don't use email addresses as user IDs

17 点作者 alloallo超过 14 年前
It should be a given that people change their email address occasionally, and so using an email address as a unique user identifier is a bad idea - but nevertheless I've seen programmers do this on occasion, and I was reminded of this today when I contacted Tradeshift (an otherwise good invoicing startup) about why I couldn't change my email, and got the reply that email addresses were being used as user IDs, but "we're working on a different solution so that in time it'll be possible to change your email address." Hmm...<p>(Note: There's nothing wrong with using email addresses for log-ins, i.e. letting users enter their email address and password when they log in. But there should always be some sort of other unique user identifier (typically an integer) so that users may change their email address without breaking any database references).

6 条评论

sambeau超过 14 年前
I have always, instinctively given an auto-generated unique ID to any table that represents an object: e.g. users, stories, payments etc.<p>Although it can often mean that you end up giving a unique ID to pretty much everything it saves these kind of problems in the long run.<p>My other long-standing trick is to mark things as deleted rather than actually removing them from the database. This allows you to un-delete things. It has saved my ass on a few occasions.
评论 #2249798 未加载
valjavec超过 14 年前
Even barcodes are not good for unique IDs in stores, since you can have same product eg. CHocolate produced in two different plants.<p>Basic rule is: never use any data as unique ID, always use an abstract field for that.
petervandijck超过 14 年前
And don't store passwords as plaintext :) That's your user table right there.
patio11超过 14 年前
Additional bad choices for primary keys: names, URLs (including OpenID identifiers), and anything else that changes.
recht超过 14 年前
You got a wrong answer. Tradeshift does not use the email as a primary key in any way, we just require uniqueness (all keys are uuid in Tradeshift). It is true that you cannot change the email yourself, but that's simply because of priorities - at the moment that functionality has been postponed in order to improve the core app instead.
评论 #2253649 未加载
getonit超过 14 年前
If it's going into a database, it has an integer index that is separate from everything else. It's the law.
评论 #2250135 未加载