<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Tom Moertel's Weblog: Tag reddit</title>
    <link>http://blog.moertel.com/articles/tag/reddit?tag=reddit</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Quality rants on programming theory and stuff geeks like</description>
    <item>
      <title>Never store passwords in a database!</title>
      <description>&lt;p&gt;Recently, the folks behind &lt;a href="http://reddit.com/"&gt;Reddit.com&lt;/a&gt; confessed
that &lt;a href="http://web.archive.org/web/20070109023445/http%3A//reddit.com/blog/theft"&gt;a backup copy of their database had been
stolen.&lt;/a&gt; Later, spez, one of the Reddit
developers, &lt;a href="http://reddit.com/info/usqe/comments/cuugl"&gt;confirmed&lt;/a&gt;
that the database contained password information for Reddit&amp;#8217;s users,
and that the information was stored as plain, unprotected text.
In other words, once the thief had the database, he had everyone&amp;#8217;s
passwords as well.&lt;/p&gt;


	&lt;p&gt;Had the folks at Reddit &lt;a href="http://en.wikipedia.org/wiki/Password_cracking#Salting"&gt;salted and
hashed&lt;/a&gt; the
passwords, the thief would now be in a very different situation.
Instead of holding all the keys to the kingdom, he would face the
prospect of a potentially expensive search for each and every user&amp;#8217;s
password he wanted to extract from the database.  The expense of the
search would likely have dissuaded him from making the attempt in
earnest, given how little exploitable value a Reddit account represents.  In
short, the passwords would have been secure, even though the database
had fallen into the thief&amp;#8217;s hands.&lt;/p&gt;


	&lt;p&gt;Why, then, didn&amp;#8217;t Reddit&amp;#8217;s programmers salt and hash the passwords
before storing them in their database?  Because, according to the
earlier post by spez, they wanted to be able to send forgotten
passwords to users via email.  It was a design decision: they
weighed the risks of having plain-as-day passwords in the database
against the convenience of being able to email users their forgotten
passwords and decided that, in the balance, convenience carried more
weight.  It&amp;#8217;s a decision they now regret.  (It&amp;#8217;s a doubly unfortunate
decision because &lt;a href="http://blog.moertel.com/articles/2007/02/09/dont-let-password-recovery-keep-you-from-protecting-your-users"&gt;you don&amp;#8217;t need to store passwords in your user database
in order to offer convenient account recovery&lt;/a&gt;.)&lt;/p&gt;


	&lt;p&gt;The reason I&amp;#8217;m writing about this event isn&amp;#8217;t to kick the
good folks at Reddit while they&amp;#8217;re down.  Rather, I&amp;#8217;m trying to make a point:&lt;/p&gt;


&lt;p style="padding-left: 2em; padding-right: 2em"&gt;&lt;strong&gt;If you are
storing passwords in a database, you are almost certainly making a
mistake.&lt;/strong&gt;&lt;/p&gt;

	&lt;p&gt;The guys at Reddit are known for being smart.  They thought they had a
good reason for storing passwords in their database.  They
were wrong.  If smart programmers can make this mistake, lots
of programmers can.  Do you think you have a good reason for storing
passwords in your database?  If so, you&amp;#8217;re probably wrong, too.&lt;/p&gt;


	&lt;p&gt;How can I be so sure?  Because, when it comes to web-app authentication,
cutting corners doesn&amp;#8217;t buy you anything. It doesn&amp;#8217;t save you coding time.
It doesn&amp;#8217;t give your users a better experience. All it does is weaken the security of your web application, needlessly putting your users, your employer, and yourself at  risk.&lt;/p&gt;


	&lt;p&gt;So please let me take this opportunity to ask if you
know of (or perhaps work on) any software systems that store passwords
as plain, unprotected text in a database.  If so, &lt;em&gt;fix your
software now&lt;/em&gt;:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Salt and hash each and every password (use an expensive hashing function such as bcrypt that was designed for password applications)&lt;/li&gt;
		&lt;li&gt;Store the salt and
hash &amp;#8211; not the password &amp;#8211; in your database. &lt;/li&gt;
		&lt;li&gt;Throw the password itself away.&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;You&amp;#8217;ll be glad you did.&lt;/p&gt;


&lt;div class="update"&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Minor edits for clarity.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 2007-02-13:&lt;/strong&gt; Salting and hashing does not get in the way of account recovery.  You do &lt;em&gt;not&lt;/em&gt; need to email users their forgotten passwords: there are other account-recovery options that are just as convenient but much more secure.  See &lt;a href="http://blog.moertel.com/articles/2007/02/09/dont-let-password-recovery-keep-you-from-protecting-your-users"&gt;Don&amp;#8217;t let password recovery keep you from protecting your users&lt;/a&gt; for more.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update 2007-10-03:&lt;/strong&gt; Revised text slightly to emphasize that there is no benefit to be had by implementing a weak password system, and therefore there is no reason &lt;em&gt;not&lt;/em&gt; to implement a secure system. Pointed more directly to bcrypt, too.
&lt;/div&gt;</description>
      <pubDate>Fri, 15 Dec 2006 13:25:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:547d5909-6007-46a3-ae22-ae1f8d348658</guid>
      <author>Tom Moertel</author>
      <link>http://blog.moertel.com/articles/2006/12/15/never-store-passwords-in-a-database</link>
      <category>web development</category>
      <category>security</category>
      <category>reddit</category>
      <category>security</category>
      <category>passwords</category>
      <category>salt</category>
      <category>hash</category>
      <trackback:ping>http://blog.moertel.com/articles/trackback/267</trackback:ping>
    </item>
    <item>
      <title>Adding reddit and del.icio.us buttons to articles in Typo</title>
      <description>&lt;p&gt;Here&amp;#8217;s quick patch I made to my &lt;a href="http://typosphere.org"&gt;Typo&lt;/a&gt; 4.0
installation to add &lt;a href="http://reddit.com"&gt;Reddit&lt;/a&gt; and
&lt;a href="http://del.icio.us/"&gt;del.icio.us&lt;/a&gt; buttons to articles.  Now one click
is all it takes to submit an article to either site.  (These buttons
appear on my blog at the end of each article.)&lt;/p&gt;


	&lt;p&gt;If you want to apply the patch, be sure to also place copies of the
button images into &lt;code&gt;public/images&lt;/code&gt;.  You can snag the
images from my site or from the Reddit and del.icio.us sites.&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s the patch:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;--- typo.orig/app/helpers/articles_helper.rb    2006-07-24 11:04:27.000000000 -0400
+++ typo/app/helpers/articles_helper.rb    2006-08-09 17:06:51.000000000 -0400
@@ -73,7 +74,26 @@
       code &amp;lt;&amp;lt; tag_links(article)        unless article.tags.empty?
       code &amp;lt;&amp;lt; comments_link(article)    if article.allow_comments?
       code &amp;lt;&amp;lt; trackbacks_link(article)  if article.allow_pings?
-    end.join("&amp;amp;nbsp;&amp;lt;strong&amp;gt;|&amp;lt;/strong&amp;gt;&amp;amp;nbsp;")
+      code &amp;lt;&amp;lt; submit_this_article_links(article)
+    end.join("&amp;amp;nbsp;| ")
+  end
+
+  def submit_this_article_links(article)
+    u_url = u(url_of(article, false))
+    u_title = u(article.title)
+    [  # move me into a database table
+      [ "Submit to Reddit.com",
+        "http://reddit.com/submit?url=&amp;lt;URL&amp;gt;&amp;#38;title=&amp;lt;TITLE&amp;gt;",
+        image_tag("reddit.gif", :size =&amp;gt; "18x18", :border =&amp;gt; 0)
+      ],
+      [ "Save to del.icio.us",
+        "http://del.icio.us/post?v=2&amp;#38;url=&amp;lt;URL&amp;gt;&amp;#38;title=&amp;lt;TITLE&amp;gt;",
+        image_tag("delicious.gif", :size =&amp;gt; "16x16", :border =&amp;gt; 0)
+      ]
+    ].map do |submit_title, submit_url, image_tag|
+      submit_url = submit_url.gsub(/&amp;lt;URL&amp;gt;/, u_url).gsub(/&amp;lt;TITLE&amp;gt;/, u_title)
+      %(&amp;lt;a href="#{h submit_url}" title="#{h submit_title}: &amp;amp;#x201C;#{h article.title}&amp;amp;#x201D;"&amp;gt;#{image_tag}&amp;lt;/a&amp;gt;)
+    end.join("&amp;amp;nbsp;")
   end

   def category_links(article)
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;The code is begging for a little refactoring love, but I&amp;#8217;m off for vacation
in about twenty minutes, so it will have to wait.&lt;/p&gt;</description>
      <pubDate>Wed, 09 Aug 2006 18:25:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:517cb441-e204-4713-94c5-321917af0d73</guid>
      <author>Tom Moertel</author>
      <link>http://blog.moertel.com/articles/2006/08/09/adding-reddit-and-del-icio-us-buttons-to-articles-in-typo</link>
      <category>site news</category>
      <category>typo</category>
      <category>hacks</category>
      <category>typo</category>
      <category>reddit</category>
      <category>delicous</category>
      <trackback:ping>http://blog.moertel.com/articles/trackback/152</trackback:ping>
    </item>
  </channel>
</rss>
