<?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>Binary Logic &#187; transition</title>
	<atom:link href="http://www.binarylogic.com/tag/transition/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.binarylogic.com</link>
	<description>Ben Johnson's thoughts and programming techniques</description>
	<lastBuildDate>Sat, 23 Jan 2010 21:19:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Tutorial: Easily migrate from restful_authentication to Authlogic</title>
		<link>http://www.binarylogic.com/2008/11/23/tutorial-easily-migrate-from-restful_authentication-to-authlogic/</link>
		<comments>http://www.binarylogic.com/2008/11/23/tutorial-easily-migrate-from-restful_authentication-to-authlogic/#comments</comments>
		<pubDate>Sun, 23 Nov 2008 22:46:00 +0000</pubDate>
		<dc:creator>benjohnson</dc:creator>
				<category><![CDATA[Authlogic]]></category>
		<category><![CDATA[migrate]]></category>
		<category><![CDATA[restful_authentication]]></category>
		<category><![CDATA[transition]]></category>

		<guid isPermaLink="false">0/2009/03/23/tutorial-easily-migrate-from-restful_authentication-to-authlogic</guid>
		<description><![CDATA[I&#8217;ve been getting a lot of emails asking the best way to migrate from restful_authentication. Where it gets complicated is in the password encryption methods. Authlogic and restful_authentication use different methods. You don&#8217;t want to change this method because it will break backwards compatibility with your current passwords, meaning no one will be able to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been getting a lot of emails asking the best way to migrate from restful_authentication. Where it gets complicated is in the password encryption methods. Authlogic and restful_authentication use different methods. You don&#8217;t want to change this method because it will break backwards compatibility with your current passwords, meaning no one will be able to log into their account. Fear not, because I did all of the hard work for you&#8230;</p>
<p><span id="more-253"></span></p>
<h2>Use the same password algorithm as restful_authentication</h2>
<pre class="ruby"># app/models/user.rb
class User &lt; ActiveRecord::Base
  acts_as_authentic do |c|
    c.act_like_restful_authentication = true
  end
end</pre>
<h2>Transition to one of Authlogic password algorithms</h2>
<p>The first thing you need to do is make sure your database field &#8220;crypted_password&#8221; and &#8220;salt&#8221; allow for the storage of at least 128 characters (assuming you are migrating to Sha512). restful_authentication uses Sha1 which is 40 characters. If you are limiting the size, you need to create a migration that looks similar to.</p>
<pre class="ruby">change_column :users, :crypted_password, :string, :limit =&gt; 128,
  :null =&gt; false, :default =&gt; ""

change_column :users, :salt, :string, :limit =&gt; 128,
  :null =&gt; false, :default =&gt; ""</pre>
<p>Now just tell acts_as_authentic what you are doing:</p>
<pre class="ruby"># app/models/user.rb
class User
  acts_as_authentic do |c|
    c.transition_from_restful_authentication = true
  end
end</pre>
<p>You could pass an optional argument to transition to any password algorithm you want. By default Authlogic uses the Sha512 algorithm, but let&#8217;s say you wanted to transition to the BCrypt algorithm. No problem</p>
<pre class="ruby"># app/models/user.rb
class User &lt; ActiveRecord::Base
  acts_as_authentic :transition_from_restful_authentication =&gt; true,
    :crypto_provider =&gt; Authlogic::CryptoProviders::BCrypt
end</pre>
<p>For more information on BCrypt <a href="http://www.binarylogic.com/2008/11/22/storing-nuclear-launch-codes-in-your-app-enter-bcrypt-for-authlogic">checkout my blog post about it</a>.</p>
<h2>What&#8217;s the difference?</h2>
<p>act_like_restful_authentication will not change a thing, your users passwords will remain in the same format. From your database&#8217;s perspective, it will be as if you are using restful_authentication.</p>
<p>transition_from_restful_authentication starts changing your users passwords using the Authlogic passwords system that you specify with the :crypto_provider option. How does it do this? It&#8217;s simple, every time a user successfully logs in and their password is encrypted with the restful_authentication algorithm it will update their password with the Authlogic algorithm. When a new account is created it will use the Authlogic algorithm. This allows your user base to slowly transition and allowing them to still be able to log in.</p>
<p>That&#8217;s it. I&#8217;m not going to go into the Authlogic set up because <a href="http://www.binarylogic.com/2008/11/3/tutorial-authlogic-basic-setup">I already have a tutorial on this</a>.</p>
<p>Let me know what you think or if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.binarylogic.com/2008/11/23/tutorial-easily-migrate-from-restful_authentication-to-authlogic/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
