Better Passwords with a Reasonable Effort

In this note, principles of good password creation are offered and discussed. At the end of the note, a process is offered to create passwords that follow the presented principles and require a reasonable mental effort.

Many “easy” tricks are offered over the web. It is up to the reader to analyze those approaches against the principles offered here.

Related topics:


Characteristics of a good password:

  • a password should be used only once for a given purpose
  • the compromise of one password should not compromise other passwords
  • a password should contain a large amount of entropy

Password used only once:
It is necessary to use a password only once. This is important in case one of your password is compromised. For example, let’s say you have an account with two services (Google and Facebook). If the same password is employed for both services, then an attacker who becomes aware of the password for one service can also access the other service.

Password compromise:
Passwords should not be related in such a way that knowledge of a password for one service reveals passwords for other services. For example, although the following passwords “123google”, “123facebook” and “123amazon” are different, an attacker discovering one would easily guess the others.


Entropy represents the amount of chaos associated with an entity. In the case of passwords, entropy is related to the number of tests an attacker would have to conduct to test all the possible passwords.

For example, if a bike lock was made of 4 numbers ranging from 1 to 8, then the total number of possible combinations would be 8 * 8 * 8 * 8 = 4096 combinations. Therefore, an attacker without knowledge of the proper combination would have to try at most 4096 different combinations to unlock the bike.

Entropy is expressed in the number of bits required to hold the total number of combinations. In the bike lock example, 4096 can be expressed in a value with 12 bits. This can be verified since 2 to the power of 12 is 4096. Each rotating wheel in the bike lock contribute 3 bits of entropy since each wheel can have 8 different position (2 ^ 3 = 8). If the same lock had only three wheels, the lock would provide only a total of 9 bits of entropy.

In the bike example, if each wheel could occupy 10 positions, instead of 8, then each wheel would provide 3.32 bits of entropy (2 ^ 3.32 = 10) and a bike lock made of four of those wheels would provide a total of 13.3 bits. Indeed, the lock provides 10 000 different combinations, which is 2 ^ 13.3.

What needs to be remembered from this exercise are the following concepts:

  • each position in a lock provides an amount of entropy
  • the larger number of combinations in a position means a larger amount of entropy
  • the total amount of entropy provided by a lock is the sum of entropy provided by each independent position in the lock

Passwords are similar to Bike Locks

A password is similar to a bike lock where each character in the password represents a mechanical wheel that can take a number of different values.

If a password is made only of lowercase letter (26 values), then each character is worth 4.7 bits of entropy.
If a password is made of lower and upper case letters (52 values), then each character is worth 5.7 bits of entropy.
If a password is made of lower and upper case letters, along with numbers and special characters (72 values), then each character is worth 6.2 bits of entropy.

To be safe, a password should have at least 64 bits of entropy. A great password should have 128 bits of entropy.

A question easily comes to mind: should each password be at least 11 characters? The answer is yes. Continue reading, a trick is given below on how to create long passwords and easily remember them.

Entropy Revisited

Astute readers might offer a password made out of words such as:


There are 11 characters in this password. Since characters range in lower and upper cases, then each character offers 5.7 bits of entropy, which would mean 62.7 bits of entropy, right? No. If a password is made out of words, then the characters are related and not independently random. Therefore, an attacker trying words and not characters might find the password in a smaller amount of tries.

There are 171,476 English words in current use (between 17 and 18 bits of entropy for each word), so OrangeApple is worth only 34 bits of entropy, not 62.7.

Password Principles Restated

Characteristics of a good password:

  • a password should be used only once for a given purpose
  • the compromise of one password should not compromise other passwords
  • a password should contain a large amount of entropy (minimum 64 bits, better if 128 bits and above):
    • many characters in the password
    • varied characters (lower and upper cases, numbers, special characters)
    • unrelated characters (avoid whole words)

Mental Approach to Creating Better Passwords

Create passwords by combining the following tricks:

  • high entropy constant reused between all passwords to provide a minimum amount of entropy
  • add a variable component based on the context the password is used
  • use a mental transformation known only to you

Constant Component
Create a long string of seemingly random characters by using a saying you want to repeat yourself. Use a phrase that means something to you. Make it a message that will improve your life, since you will type it all the time. For example:


The above string of characters can easily be remembered if one uses the phrase: “Rotate Your Tires Every 8000 Kilometers!”. This component yields approximately 72 bits of entropy.

Variable component
This is the easiest part. The variable component should be based on the context in which the password is used. If this is a password for Google, then the variable part could be “google”. If the password is used to unlock your laptop, then the variable part could be “laptop”. The variable component should be easy for the password owner to recall from the context in which the password is used.

Mental Transformation
The aim of the mental transformation is to hide the variable part from a potential attacker. Continuing the examples above:

Password for Facebook: AfRoYoTiEv8Ki!cebook

Password for Google: OgRoYoTiEv8Ki!ogle

In these examples, the mental transformation consists of:

  • taking the first two letters of the variable component, reversing them and putting them in front of the constant component; and,
  • taking the remainder of the variable component and appending after the constant component.

In these examples, the entropy provided by the password is always at least 72 bits. The approach follows the presented password principles and, with a bit of practice, requires little mental effort.

Each reader should find for himself/herself a suitable mental transformation which is personal and original.

Writing a Reduce Function in CouchDb

This note relates to:

  • CouchDb version 1.0.1
  • curl version 7.21.0
  • Ubuntu 10.10


This article discusses some of the details in writing a reduce function for a CouchDb view. A reduce function is used to perform server-side operations on a number of rows returned by a view without having to send the rows to the client, only the end result.

The tricky part of reduce functions is that they must be written to handle two “modes”: reduce and re-reduce. The signature of a reduce function is as follows:

If the parameter “rereduce” is reset (false), then the function is called in a “reduce” mode. If the parameter “rereduce” is set (true), then the function is called in a “re-reduce” mode.

The aim of a reduce function is to return one value (one javascript entity, a scalar, a string, an array, an object…) that represents the result of an operation over a set of rows selected by a view. Ultimately, the result of the reduce function is sent to the client.

The reason for the two modes is that the reduce function is not always given at once all the rows that the operation must be performed over. For efficiency reasons, including caching and reasons related to database architecture, there are circumstances where the operation is repeated over subsets of all rows, and then these results are combined into a final one.

The “reduce” mode is used to create a final result when it is called over all the rows. When only a subset of rows are given in the “reduce” mode, then the result is an intermediate result, which will be given back to the reduce function in “re-reduce” mode.

The “re-reduce” mode can be called once or multiple times with intermediate results to produce the final result.

Therefore, the tricky part of reduce function is to write them in such a way that:

  1. the keys and values from a view can be accepted as input
  2. the result must be convenient as the output for the client
  3. the result of the reduce function must be accepted as input in the case of “re-reduce”

The remainder of this note is an example of a reduce function that computes simple statistics over a set of scores. The example follows these steps:

  1. Create a database in CouchDb
  2. Install a design document with the map and reduce function that is tested
  3. Load a number of documents, which are score results
  4. Request the reduction to access the expected statistics

In this example, it is assumed that the CouchDb database is located at Also, it is assumed that there are no assigned administrators (anyone can write to the database).

Create Database

curl is used to perform all operations.

Install Design Document

Create a text file named “design.txt” with the following content:

Load design document:

Load Documents

Consume View and Reduction
To see the output of the view:

The following result should be reported:

To include the reduction:

which should lead to this report:

Watching the reduction
Looking at the CouchDb logs helps in the understanding of the steps taken by the reduction function:

Add more document:

Some of the logs show the function used in “reduce” mode:

Some of the logs show the function used in “re-reduce” mode:

To help understanding, let’s reproduce the content of the reduce function, here:

In “reduce” mode, the parameter “keys” is populated with an array of elements, each element being an association (array) between a key and a document identifier. In that mode, the parameter “values” is an array of values reported by the view. In the example above, the first part of the function is skipped during the “reduce” mode. The last part of the fucntion accepts scalar values and computes top, bottom, sum and count of the scores. Finally, it computes an average over those scores.

As discussed earlier, this result can be the final result, or an intermediate result. It is impossible for the reduce function to predict how the result is to be used.

In “re-reduce” mode, the parameter “keys” is null while the parameter “values” contains a set of intermediate results. In the example above, the first part of the function is used to merge the intermediate results into a new one. This new result could be the final result, or it could be a new intermediate result.

Reduce functions over subset of a View

A reduction does not have to be over the complete set returned by a view. For example, to see only a subset:

yields only some students:

If reduction is included:


Reduce functions can be tricky because of the dual usage. The modes in use are controlled by the CouchDb database and the person designing a reduce function must take into account the various permutations.

NOTE:Do not leave the log statements in view map and reduce functions since they degrade performance.

Remove document duplicates from CouchDb view query using a list function

This note relates to CouchDb 1.0.1

In CouchDb, documents accessible via a view can be mapped to multiple keys. When querying for multiple keys, it is possible for a document to be returned multiple times. In some circumstances, this might be the desired behaviour. However, when the desired semantics are to retrieve only one copy of each document matching any key, without duplicates, a different approach is required.

As a note of caution, this article might provide a complicated solution to a problem easily solved another way. I was under the impression that the work covered here could be easily done using a special flag on a view query. However, I can not readily find it. I am hoping someone will come around and comment on this article with a simpler approach. Until then, the solution presented here will suffice.

The result of a view query is a JSON object that contains an array of rows, each row reporting a document matching the query. A list function is used to transform the result of a view query into a format desired for output. One advantage of using a list function is that a list function has a chance of inspecting each row (or document) before sending to the output.

In this approach, we use a list function to output a result in the exact same format as a view query, suppressing duplicates of documents that were already sent.

The following list function is generic enough to be used any view that emit the documents as values:

The input parameter called “head” is used to retrieve the total number of rows and the offset. Then, the list function outputs the “rows” member. Each row is sent as a JSON string, so the list function must take care of inserting the commas at the right place. A map (javascript object) called “ids” is used recall which documents have already been sent. The key used in the map is the identifier of the document. When a document has already been sent, it is skipped.

For example, if a query to a view named “testview” yielded duplicates of a document using the following URL:
then duplicates would be removed if the above function was named “noduplicate” and the following URL employed:

In conclusion, the presented function is generic enough to be reused in many situations. However, I suspect that a much easier way to perform this will be designed shortly, if it does not already exist.

Fix dpkg available file in Ubuntu

This note relates to Ubuntu Maverick Meerkat (10.10) but it might apply to other versions, as well.

I wrote this note after my system became unstable following a number of configuration shenanigans. What did not help is that I had just upgraded from 10.04 to 10.10. Therefore, I am not sure that I can explain how to get to the state my platform was in.

Symptom: Every time an apt-get command is run, some sort of error or warning is reported stating that an available package has a corrupt version number.

Cause: The ‘available’ file used by dpkg contains erroneous information or is corrupted.

Solution: Rebuild the ‘available’ file.


1. Back up current file

2. Delete current ‘available’ file

3. Rebuild ‘available’ file

After these steps, commands to ‘apt-get’ should no longer complain about available versions.

Re-install GNOME-Session in Ubuntu

This note was written while using Ubuntu 10.10. However, it might apply to other versions as well.

Symptoms: After a number of shenanigans involving configuration, I found myself unable to login to the desktop, in Ubuntu. The login screen (GDM) offered my user name. However, once my user name was selected, no session were offered. Entering my password and pressing the login button would show a brief blank screen and then return me to the login screen.

Cause: Somehow, the gnome-session was removed from installation.

Solution: Re-install gnome-session

Here is the recipe:

  1. At the login screen (GDM), press the key combination CTL-ALT-F1. This should drop you out of GDM and into a terminal screen
  2. Login to the terminal using your username and password
  3. At the prompt, enter the command “sudo apt-get install gnome-session”
  4. Then, “sudo reboot”

If the gnome-session was already installed and you get an error attempting to install it again (or the answer “gnome-session is already installed”), then reconfiguring it might suffice: “sudo dpkg-reconfigure gnome-session”

Quickly install most CODECs in Ubuntu 10.04

Installing restricted CODECs is easier in Ubuntu 10.04 than in previous versions.


Installing CouchApp on Ubuntu 10.04

CouchApp is a python tool to help develop, upload and clone applications meant for couchDb. Those applications are also known as “couchApps”.

The following recipe is used to install couchapp on Ubuntu 10.04. To use couchapp, you probably first need to install “couchdb”, but this is readily available from the usual repositories.

The issue in installing couchapp on Ubuntu 10.04 is that one needs to rely on some personal packages made available via

Warning: This recipe installs keys from developers on your platform. From this point on, your platform will trust packages made available from those individuals.

From a high level view, two packages are required:

  1. add-apt-repository: utility tool to easily add a new repository
  2. couchapp : the python tool itself
  3. python-restkit: a python library that couchapp is dependent on

Installing add-apt-repository

Installing python-restkit

Installing couchapp

Use a 24-hour clock in Ubuntu

This note applies to:

  • Ubuntu Lucid 10.04
  • Mozilla Thunderbird 3.0.8
  • Mozilla Lightning 1.0b1


I am a fervent user of the 24-hour clock. However, when I install a new platform, I often accept the default locale of en_US.UTF8. In general, I do not mind this locale. However, applications such as Thunderbird use the locale to adjust the display of various elements, including time. It affects also plug-ins such as Lightning.

This note is a receipt that changes the default time display from 12-hour clock to 24-hour clock.

  1. Edit the default locale file
  2. Add the following line at the end of the default local file:
  3. Reboot the computer… (yeah, it is lame)

That’s it! From then on, applications that follow the locale will display the time in 24-hour clock format.

To verify that you successfully changed the locale, use the locale command:

The entry LC_TIME=en_DK.UTF-8 should be displayed.

Export and Import custom key bindings in Eclipse

This note relates to Eclipse 3.6.0

Eclipse saves a user’s preferences in a special area of the workspace directory. In fact, it saves all the information in the sub-directory called “.metadata”. If you use multiple workspaces or need to create a fresh new workspace, when you first start the workspace, you will find out that all the key bindings and other preferences are lost. Copying the “.metadata” directory between two workspaces is not an option since it also contains the information about the projects.

The process needed to copy the user’s preferences between two workspaces is to export them from the workspace containing the favoured ones, and importing them in the desired workspace. In the process, Eclipse produces a text file with an “.epf” extension which can be used to port the preferences between workspaces.

To produce the exported preferences file, use the Eclipse menu:

  • File > Export… > General > Preferences > Next
  • At this page, select what should be exported. For exporting only key bindings, unselect “Export All” and check “Keys Preferences”
  • Specify a file to save the preferences to
  • Press “Finish”

To import the preferences file, using the Eclipse menu:

  • File > Import… > General > Preferences > Next
  • Browse for the desired preferences file
  • Click “Finish”

Although there exists, in the preferences page where key bindings are assigned, a button offering to export key bindings in a CSV file, I do not know how to use the produced CSV file restore key bindings in the different workspace. The .epf method, described above, is the only one I know, so far.

Use CTL-Tab for switching editor windows in Eclipse

This note relates to Eclipse SDK 3.6.0

Many development platforms and editors use the key combination CTL+Tab to switch between edited windows. In Eclipse, the default key combination is CTL+F6. However, the Eclipse platform is customisable and the key combination can easily be changed.

In using the Eclipse menu:

  • Window > Preferences > General > Keys
  • Select the command titled “Next Editor”
  • Click mouse in text box titled “Binding” and select all text
  • Press the key combination CTL+Tab. The text in the box should reflect the action
  • Press the button “Apply”

While you are at it, you should assign the binding “Shift+CTL+Tab” to the command titled “Previous Editor”

To back up your key bindings or port them into a different workspace, use the note in exporting and importing key bindings.