abe hassan | blog: off by one on purpose

Here are two problems that we ran into at LiveJournal: In a paginated system, how do you know whether to display the next/previous links? With password prompts being masked out, how can you tell a user that they kept typing but the prompt didnt record more? In the first case: if you display 20 items per page, load 21. If you have 21, throw out the last one and add the pagination links. If you get 20, then you know its exactly right. Doing a database query with a "LIMIT 20" doesnt give you enough information to do this.In the latter case, its also easy: if your system limits passwords to say 15 characters, then make the change-password prompt take 16 characters. If the person typed in exactly 15 characters, then youre great. If you got 16, you can tell them that you didnt save their password the way they think you did.I love this idea. In order to gain certainty about something, you might just need one more piece of information. This trick is a bit clever and comes up every so often.

via abe hassan | blog: off by one on purpose.