<?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>Top Down View &#187; php</title>
	<atom:link href="http://www.topdownview.com/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.topdownview.com</link>
	<description>My View Of The World</description>
	<lastBuildDate>Fri, 20 Aug 2010 05:13:52 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=abc</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Protecting Your Users&#8217; Passwords &#8211; Part 2</title>
		<link>http://www.topdownview.com/2010/04/protecting-your-users-passwords-part-2/</link>
		<comments>http://www.topdownview.com/2010/04/protecting-your-users-passwords-part-2/#comments</comments>
		<pubDate>Sat, 10 Apr 2010 02:39:40 +0000</pubDate>
		<dc:creator>Jon Jennings</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.topdownview.com/?p=339</guid>
		<description><![CDATA[Last week I showed you how NOT to store your users&#8217; passwords in your database: the biggest sin of all is storing them as plaintext and the &#8216;false sense of security&#8217; solution is to apply a hashing algorithm to them.
We saw that we can use a common hashing algorithm (the algorithm I used is called [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.topdownview.com/2010/03/protecting-your-users-passwords/">Last week</a> I showed you how NOT to store your users&#8217; passwords in your database: the biggest sin of all is storing them as plaintext and the &#8216;false sense of security&#8217; solution is to apply a hashing algorithm to them.</p>
<p>We saw that we can use a common hashing algorithm (the algorithm I used is called MD5: <a href="http://en.wikipedia.org/wiki/MD5">http://en.wikipedia.org/wiki/MD5</a>) to turn &#8220;donkey&#8221; into &#8220;9443b0fceb8c03b6a514a706ea69df0b&#8221; and I told you that there&#8217;s no programmatic way to turn that back into &#8220;donkey&#8221; &#8211; the hashing algorithm is one-way. However, if you did last week&#8217;s homework and pasted that ciphertext into a search engine you&#8217;ll have found you got <a href="http://www.google.ca/search?sourceid=chrome&amp;ie=UTF-8&amp;q=9443b0fceb8c03b6a514a706ea69df0b">many returns</a>. Why?</p>
<p>A little history: when the commonly used hashing algorithms were created, they were designed to be computationally &#8220;expensive&#8221;. That means they take a lot of processor power (and hence time) to calculate. This was deliberate &#8211; a user only has to login occasionally so it didn&#8217;t matter if it took 2 or 3 seconds to check their password. The excellent side effect of this delay was that it prevented a hacker from trying to guess your password by brute-force. Even assuming you&#8217;d been silly and used a dictionary word as your password, a hacker couldn&#8217;t break into your account by trying every word in the dictionary as he&#8217;d be there for a very long time. A quick calculation with my machine&#8217;s dictionary says, taking 3 seconds per attempt, it would take 3.4 days to attempt every dictionary word. Unfortunately for hashing algorithms, computers have got very much faster in the last 20 years &#8211; even my little laptop can generate a hash in 0.04 seconds. Suddenly the time to run through the entire dictionary has shrunk to one hour and our apparent security has vanished.</p>
<p>Things get even worse though. If you have a dictionary word as your password and I have access to a hash of it, I can tell you your password in just 5 seconds. I paste the hash into a search engine &#8211; one click on &#8220;search&#8221; and I have your password. What&#8217;s happened is that hackers have done all the hard work up front &#8211; they&#8217;re already run entire dictionaries through the common hashing algorithms and they&#8217;ve posted the lists of words and hashes on the internet where search engines have found them and indexed them. So although it&#8217;s technically true that we can&#8217;t take a hash value and &#8220;unhash&#8221; it, hackers do have access to functionality that can perform a similar job &#8211; for single words.</p>
<p>&#8220;OK&#8221;, I hear you say, &#8220;but I&#8217;d never be stupid enough to just use a plain dictionary word as my password &#8211; I&#8217;ll put a number on the end of it&#8221;. Right then&#8230; that might help, but it might not&#8230; <a href="http://www.google.ca/search?hl=en&amp;safe=off&amp;q=8339e38c61175dbd07846ad70dc226b2&amp;meta=&amp;aq=f&amp;aqi=&amp;aql=&amp;oq=&amp;gs_rfai=">8339e38c61175dbd07846ad70dc226b2</a> and <a href="http://www.google.ca/search?sourceid=chrome&amp;ie=UTF-8&amp;q=2484b2d1aec71de2ca87f88af401a6af">2484b2d1aec71de2ca87f88af401a6af</a> are hashes of dictionary words with numbers on the end and both are indexed by Google (vote1234 and password99 in case you can&#8217;t be bothered checking). Although if your password is &#8220;aardvark50&#8243; then you&#8217;re safe as its hash 0913c211b2eaa2a8b3b11fe53bdf9b4f doesn&#8217;t appear on the internet (until now of course because Google will index this blog post and your secret will soon be out!).</p>
<p>So how should we, as programmers, prevent our users&#8217; passwords being cracked like this? The answer is surprisingly simple. We concatenate the password with some other information before we hash it.</p>
<p>The best approach is two-pronged. Firstly we concatenate with a fixed nonsense string eg &#8220;78g^&amp;FB%V^&amp;I&#8221; &#8211; this ensures that, however simple a password the user has entered, we&#8217;ve created something that&#8217;s pretty much guaranteed to never have existed as a string before in the history of the Internet.  Secondly we also concatenate it with a piece of information that&#8217;s specific to that user on our site eg their username. This is just icing on the cake to make sure that the hashing is different for each user &#8211; so if two users use the same password then their hashes will be different. The procedure is the same as before: we apply this &#8220;super-hash&#8221; to the password that the user initially sets before we store it in our database and we apply the same &#8220;super-hash&#8221; to the user&#8217;s password attempt before we check it against the database entry.</p>
<p>So now, if user &#8220;smith&#8221; sets their password as &#8220;donkey&#8221;, the hash that we&#8217;re storing is the hash of &#8220;smithdonkey78g^&amp;FB%V^&amp;I&#8221;. Good luck finding an online hash dictionary that contains THAT!</p>
<p>Incidentally, my previous post is currently the second return on Google for &#8220;9443b0fceb8c03b6a514a706ea69df0b&#8221; (the hash of &#8220;donkey&#8221;) and I&#8217;ve actually had incoming traffic from that as a search term, so we KNOW that people are actually using search engines to crack hashed passwords like this. Consider yourself warned and make your code secure.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.topdownview.com/2010/04/protecting-your-users-passwords-part-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Protecting Your Users&#8217; Passwords</title>
		<link>http://www.topdownview.com/2010/03/protecting-your-users-passwords/</link>
		<comments>http://www.topdownview.com/2010/03/protecting-your-users-passwords/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 20:15:33 +0000</pubDate>
		<dc:creator>Jon Jennings</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://www.topdownview.com/?p=322</guid>
		<description><![CDATA[I&#8217;m currently working on a PHP-based web site that stores member details &#8211; username, address, password etc in a database. Nothing unusual here&#8230; literally millions of web sites on the internet are doing exactly the same thing.
But password storage is a dangerous area. Every month we hear about a high-profile web site being hacked into and all [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m currently working on a PHP-based web site that stores member details &#8211; username, address, password etc in a database. Nothing unusual here&#8230; literally millions of web sites on the internet are doing exactly the same thing.</p>
<p>But password storage is a dangerous area. Every month we hear about a high-profile web site being hacked into and all the user accounts made public together with their passwords. This is not good &#8211; especially as it&#8217;s fairly common for users to keep the same password across all of the sites they access.</p>
<p>Good web site security is about defence in depth. Yes, you set up security so that hackers hopefully can&#8217;t get access to your site&#8217;s files and databases. But you shouldn&#8217;t stop there. Any site whose password list has been published has made one other simple and easily avoidable mistake: they&#8217;ve made the mistake of storing their users&#8217; passwords in plain text.</p>
<p>Storing passwords in plaintext is a dangerous mistake that&#8217;s easily avoided &#8211; there&#8217;s a much smarter way to do it and it involves something called a hashing algorithm. A hashing algorithm is a form of encryption which is ONE WAY i.e. you can convert the plaintext to the encrypted form (know as ciphertext) but you can&#8217;t convert it back again. For example, if you start with &#8220;donkey&#8221; and run it through a well-known hashing algorithm you end up with &#8220;9443b0fceb8c03b6a514a706ea69df0b&#8221;. In theory, there&#8217;s no easy way to go the other way and turn that back into &#8220;donkey&#8221;.</p>
<p>But how the heck does this help us with passwords? Surely we&#8217;re going to have to turn the encrypted password back to plaintext in order to check it? Nope &#8211; there&#8217;s a neater way of doing this.</p>
<p>When the user initially sets their password, we run the hashing algorithm on the plaintext password and generate a hashed version of it. We store that hashed version in our database. When a user attempts to login, we hash their password attempt and compare THAT to the ciphertext of the previously hashed password that we&#8217;ve stored. Because the hashing algorithm is repeatable, if the password they attempted to login with matches the password they setup originally, then the two hashed ciphertexts will match too and we&#8217;ll successfully validate their login.</p>
<p>There&#8217;s no excuse for not knowing about this design pattern &#8211; Unix &amp; Linux systems have been handling user passwords in this way for the last 30 years.</p>
<p>When you implement a system like this, there&#8217;s one thing you CAN&#8217;T do. And that&#8217;s recover a password that a user&#8217;s forgotten. Remember that the hashing algorithm is one way. You can&#8217;t turn &#8220;9443b0fceb8c03b6a514a706ea69df0b&#8221; back into &#8220;donkey&#8221; when the user can&#8217;t remember their password. As a result of this you should, as a user, be very wary of any websites which offer to email you your password when you&#8217;ve forgotten it. If they can email your password to you then they&#8217;re not using a hashing algorithm to store it in their database and therefore their database is not secure should a hacker get access to it. As a programmer, if you use a hashing algorithm to safeguard your users&#8217; passwords then all you can do if a user has forgotten their password is to generate a new one for them (or let them set a new one themselves). This is generally done via an email that you send them &#8211; either containing a new random password that you generated for them or (better still) a one-off link that gives them access to a special page on the website where they can set a new password.</p>
<p>OK then, we&#8217;re sorted are we? Everything&#8217;s secure and protected from the hackers? Unfortunately not.</p>
<p>DO NOT IMPLEMENT WHAT I&#8217;VE JUST DESCRIBED.</p>
<p>There&#8217;s a flaw and I&#8217;ll tell you in a few days what that flaw is. In the meantime, you might like to paste that ciphertext into your favorite search engine and wonder about what just happened.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.topdownview.com/2010/03/protecting-your-users-passwords/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BCIT Term Wrapup</title>
		<link>http://www.topdownview.com/2009/08/bcit-term-wrapup/</link>
		<comments>http://www.topdownview.com/2009/08/bcit-term-wrapup/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 18:50:02 +0000</pubDate>
		<dc:creator>Jon Jennings</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[BCIT]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[toastmasters]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://www.topdownview.com/?p=213</guid>
		<description><![CDATA[A good term at BCIT this Spring. A very good term, both in terms (oh dear!) of course enjoyment and in terms of marks.
I took the 12 week &#8216;XML For Web Applications&#8217; COMP2899 course downtown. My first course at the downtown campus &#8211; it&#8217;s really nice there: very modern and shiny. Course was also excellent [...]]]></description>
			<content:encoded><![CDATA[<p>A good term at <a href="http://www.bcit.ca/">BCIT</a> this Spring. A very good term, both in terms (oh dear!) of course enjoyment and in terms of marks.</p>
<p>I took the 12 week &#8216;XML For Web Applications&#8217; <a href="http://www.bcit.ca/study/courses/comp2899">COMP2899</a> course downtown. My first course at the downtown campus &#8211; it&#8217;s really nice there: very modern and shiny. Course was also excellent &#8211; interesting material&#8230; I never knew you could do so much with XML and there was so much XML capability built into every browser. I knew about basic XML, DTDs, XPATH and parsers already but the course also taught schemas, XSLT and web services &#8211; overall very interesting. The course required quite a lot of learning but the labs, assignments and tests were all very fair &#8211; basically just to show that you&#8217;d done and understood the lecture content. I got a 99% mark which I&#8217;m very pleased with &#8211; especially so because the final exam was closed book with no &#8216;cheat sheet&#8217;!</p>
<p>I took the XML course for several reasons. Partly because XML interests me &#8211; all applications need configuration data and free-format text files are a recipe for disaster. Partly because I&#8217;m trying to complete the <a href="http://www.bcit.ca/study/programs/6445acert">Advanced Java Development Certificate</a> program and none of the courses I still needed were running this term. There&#8217;s one required course which hasn&#8217;t run for at least 18 months! I emailed the part-time studies director and he recommended the XML course. The course isn&#8217;t on the Java program but apparently there&#8217;s a re-organization coming which will put it on there (although another 5 months have passed now and the XML course hasn&#8217;t been added to the Java program and the lost required course still hasn&#8217;t run).</p>
<p>Having looked at the XML course I noticed that it&#8217;s also part of the <a href="http://www.bcit.ca/study/programs/6455acert">Web Application Software Development Certificate</a> program. I looked at that program and was amazed&#8230; not only are all the courses on things I&#8217;m interested in, I&#8217;ve already done half of them! So now I have TWO goals.</p>
<p>Over the last year, I&#8217;ve come across small pieces of PHP in several places. Tweaking WordPress themes has exposed me to some, and the BCIT AJAX course has required writing some PHP to handle the server-side functionality but this has pretty much all been self-taught. So when I noticed that a PHP course, <a href="http://www.bcit.ca/study/courses/comp1920">COMP1920</a>, was part of the Web Development program and there was an accelerated version coming up, I signed up immediately.</p>
<p>The PHP course was really eye-opening. For starters, it was the standard 12 week syllabus condensed into 6 Saturdays &#8211; you do one &#8216;evening&#8217; in the morning and the next &#8216;evening&#8217; in the afternoon. The course itself started out at the basics as some of the students hadn&#8217;t even programmed before, let alone seen PHP. But with the workload doubled, I was very happy with the pace.</p>
<p>The course lecturer makes an incredible difference to any course and the PHP course reintroduced me to the best lecturer I&#8217;ve had at BCIT. Jason Harrison is a programmer&#8217;s programmer &#8211; he isn&#8217;t there to teach you the theory, the 20 different parameters you can use with a function, he&#8217;s there to teach you how to get results. Jason teaches the course as 80% programming and 20% business. One of the things that PHP is great for is rapidly developing web-based applications and so a lot of people make a lot of money from using it. It seemed that most of the students had signed up for the course with that in mind and so we were all as spellbound when Jason started offering advice about business strategy as when he introduced the fopen() function. Actually&#8230; maybe more so!</p>
<p>I&#8217;m used to lecturers emphasizing the evils of cheating and the need for students to complete their work on their own but Jason&#8217;s approach is the opposite. Yes, work that you hand in has to be written by you, but there&#8217;s nothing wrong with consulting other students for advice. After all, that&#8217;s what you&#8217;d do in the real world. In the PHP course, Jason takes it a stage further &#8211; there are sections of the course which you MUST complete with other students &#8211; some parts in pairs and the final assignment as a team. The final assignment was something I&#8217;ve never seen on a BCIT course. The brief was to form a team, research something related to the course material that might be of interest to the other students and then give a 30 minute presentation &#8211; complete with demonstration and class exercise.</p>
<p>The course work was great. Because we were working at double pace, the first half of the course was heavily loaded with labs to be submitted each week. The second half of the course had coding assignments, the final assignment and revision all falling over each other. This generated a terrific buzz &#8211; I was writing up our class exercise, struggling with PHP session management and guiding other students through their problems simultaneously. Again, just like the real world.</p>
<p>Everything came together wonderfully. The final coding assignment had two options: the easy option was marked to a maximum of 100%, the hard option was marked to a maximum of 115%. Unfortunately there was no overlap between the two projects&#8230; so you had to make a decision at the beginning and stick with it. I chose the hard option and got bogged down in session management for a bit but once I&#8217;d conquered that it came together well &#8211; I even had time to extend it beyond the requirements with a bit of personal flourish. Our presentation on email injection, form validation and <a href="http://en.wikipedia.org/wiki/CAPTCHA">CAPTCHA</a> went very smoothly. I presented the class exercise on getting the other students to add a CAPTCHA test to an existing PHP form &#8211; went OK, most of the students managed to complete it and I think I answered all the questions well. It seems my Toastmasters experience showed through&#8230; I&#8217;d mentioned that I was in Toastmasters at the beginning of the course but not had any feedback. After my presentation I had THREE different people come up to me and ask me for more information. Because of the compressed timetable we had a short break after the presentations and then straight into the final exam, no time to rest on our laurels!</p>
<p>Overall I loved the course&#8230; content, lecturer, format all worked very well. Oh and I was very pleased with my mark as well&#8230; 100% <img src='http://www.topdownview.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Jason also teaches an advanced PHP course but for some reason it&#8217;s only scheduled once a year. I&#8217;m itching to get on that course!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.topdownview.com/2009/08/bcit-term-wrapup/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
