<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Programmer's testimony &#187; Password</title>
	<atom:link href="http://en.jakubiak.info/tag/password/feed" rel="self" type="application/rss+xml" />
	<link>http://en.jakubiak.info</link>
	<description>My experience with: Java, JEE, Adobe Flex, PHP, Video</description>
	<lastBuildDate>Wed, 25 Nov 2009 19:02:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Password generation</title>
		<link>http://en.jakubiak.info/2009/10/21/password-generation.html</link>
		<comments>http://en.jakubiak.info/2009/10/21/password-generation.html#comments</comments>
		<pubDate>Wed, 21 Oct 2009 19:58:52 +0000</pubDate>
		<dc:creator>Antoni Jakubiak</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Maven]]></category>
		<category><![CDATA[Password]]></category>

		<guid isPermaLink="false">http://en.jakubiak.info/2009/10/21/password-generation.html</guid>
		<description><![CDATA[This summer, I wrote some useful java classes for generating random passwords. Creating random password can be useful in situations such as the following: A user forgot his password for our application. Our application sends an email with a new temporary password. We want to verify, if a mobile phone number submitted by user is [...]]]></description>
			<content:encoded><![CDATA[<p>This summer, I wrote some useful <a href="http://code.google.com/p/jakubiak-generators/" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jakubiak-generators/?referer=');">java classes for generating random passwords</a>.</p>

<p>Creating random password can be useful in situations such as the following:</p>
<ul>
	<li>A user forgot his password for our application. Our application sends an email with a new temporary password.</li>
	<li>We want to verify, if a mobile phone number submitted by user is correct. Our application sends an SMS with the new temporary password.</li>
	<li>A user of our application creates a new account for his colleague or family member. Our application creates a temporary password for that account.</li>
	<li>For our own purposes. We want to create a good password for our personal usage.</li>
</ul>
<p>Creating a random password is not so easy as might by thought. There are two commons errors with this:</p>
<ol>
	<li>The password generated is <strong>an inelegant word</strong>, for example: &#8220;1something2&#8243;. We doesn&#8217;t want to send such a password to our potential clients.</li>
	<li>The password generated contains <strong>problematic characters</strong>, for example: &#8220;1&#8243; and &#8220;l&#8221; or &#8220;O&#8221; and &#8220;0&#8243;. There is a problem, when the user rewrites the password from one device to another, e.g.: from a mobile phone to a web application running on a laptop.</li>
</ol>
<p>That&#8217;s why in my application I create password in the form: 2 letters followed by 1 digit followed by 2 letters followed by 1 digit and so on. For example: ab2cd3ef4. Of course,  the randomly – generated password contains only safe characters.</p>

<p>I decided to publish this classes to the open source community. You can use my library in your application on <a href="http://www.gnu.org/licenses/lgpl.html" onclick="pageTracker._trackPageview('/outgoing/www.gnu.org/licenses/lgpl.html?referer=');">LGPL</a> terms. Here is an example of usage:</p>
<pre>// create a new one time password for sending via sms or email
// (4 chars - about 1e5 unique combination)
String password = new <a href="http://code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/PasswordGenerator.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/PasswordGenerator.java?referer=');">PasswordGenerator</a>().generate();</pre>
<pre>// create a new strong password
// (8 chars - about 1e10 combination)
String strongPassword = new <a href="http://code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/StrongPasswordGenerator.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/StrongPasswordGenerator.java?referer=');">StrongPasswordGenerator</a>().generate()</pre>
<p>Using this library is simply for maven2 fans. If you are not already a fan of maven2, I advise you to become one. In your maven2 application in pom.xml file add a dependency:</p>
<pre>&lt;dependency&gt;
  &lt;groupId&gt;eu.jakubiak&lt;/groupId&gt;
  &lt;artifactId&gt;jakubiak-generators&lt;/artifactId&gt;
  &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
&lt;/dependency&gt;</pre>
<p>You have to download and build the source by typing:</p>
<pre>svn checkout http://jakubiak-generators.googlecode.com/svn/trunk/ jakubiak-generators-read-only
cd jakubiak-generators-read-only/jakubiak-generators/
mvn clean install</pre>
<p>You should see the success message. Now the installation is completed and you can use this library.</p>

<p>By the way, I also wrote classes for creating a random MD5 number and for creating a random key. MD5 is obvious. The random MD5 numbers are commonly used in web applications, for example as a session cookie. In such a scenario a <a href="http://code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/KeyGenerator.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/KeyGenerator.java?referer=');">KeyGenerator class</a> is an improved replacement for the <a href="http://code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/Md5HexGenerator.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/Md5HexGenerator.java?referer=');">random MD5</a>. The KeyGenerator class create a huge random number <a href="http://www.wolframalpha.com/input/?i=(26+%2B+26+%2B+10)%5e22+%3E+2%5e128" onclick="pageTracker._trackPageview('/outgoing/www.wolframalpha.com/input/?i=_26+_2B+26+_2B+10_5e22+_3E+2_5e128&amp;referer=');">bigger than the MD5</a>. (&#8220;Bigger&#8221; in this case means a potentially larger number is possible). This number is encoded using 62 safe for URLs chars: a-z, A-Z, 0-9. Thanks to that its string representation is shorter and more safe than a hexadecimal encoded MD5.</p>
<pre>// create a statistically unique key
// (22 chars safely for URLS - about 2e39 unique combination)
String key = new KeyGenerator().generate();</pre>
<pre>// create a random MD5 and encode it hexadecimal
// (32chars - 2^128 combination)
String md5 = new Md5HexGenerator().generate();</pre>
<p>You can also write your own generator, by implementing <a href="http://code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/IGenerator.java" onclick="pageTracker._trackPageview('/outgoing/code.google.com/p/jakubiak-generators/source/browse/trunk/jakubiak-generators/src/main/java/eu/jakubiak/generators/IGenerator.java?referer=');">IGenerator</a> interface.</p>]]></content:encoded>
			<wfw:commentRss>http://en.jakubiak.info/2009/10/21/password-generation.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
