What is an API?

api Sometimes as developers, we have things we need to do that we wish someone else could do for us. Chances are someone might have already done it for you. When you start programming you learn to do stuff on your own. Later, you learn of libraries and tools you can use from other developers. Sometimes, you might want to access another developer’s data, tools, or resources. Good examples of these things might be; getting Facebook friends, adding something to a calendar, or processing some data.

These types of activities might be out of the question, or hard to achieve on your own. However, many developers have APIs or Application Programming Interface that you can use. These might be free, or cost a little bit of money. The great thing about APIs is that they are EVERYWHERE. I am going to start off basic here and go into more depth in future posts. I just want to open your eyes to the opportunities.
Continue reading “What is an API?”

PHP Ternary Operator the One Line If Else

I don’t know if it is just me or not; I have always liked optimizing my code. The awesome feeling when you learn that new trick and you cut your code from ten to three lines. It’s like leveling up in a game (insert Link getting loot sound here).

One of the biggest moments I can remember is when I discovered the Ternary Operator. What is that you ask?: It is basically an if/else statement on one line. Let’s look at an example of typical code.

if($level >= 10) {
    $sword = 'LEGENDARY';
} else {
    $sword = 'Pointy Stick';

So here we have five lines of code. It seems pretty straightforward, but can we optimize it more?: Yes, we can!
Continue reading “PHP Ternary Operator the One Line If Else”

PHP 5.5+ Secure Password Hashing

PHP 5.5+ Password Hashing
PHP 5.5+ Password Hashing
PHP’s approach to password hashing has quite a history. These methods still litter the tutorials and guide new developers down dangerous paths. Let us take a look at the history so you know where you stand. Even though this post is for PHP, this history may still affect you.

Bad: Raw Password Storage
The first method was just to store the user’s password in plain text just like the user entered it. It was easy; the user would enter their password, and you would just compare the two passwords. If they matched, you were done.

The Issue: If a hacker gets access to your database or somehow gets a user’s password to print out on the screen then it’s over.

Bad: Encrypting Passwords
The next way a developer might think about storing passwords is by encrypting them. The developer takes the user’s new password encrypts it and saves that to the database. When the user goes to login again, you simply take the encrypted password out decrypt it, compare it and success.

The issue: This is still reversible, and the hacker can still decrypt the passwords to what the user entered if the database is hacked. The user, hacker, and even you as the developer should never be able to see the password after it is saved.
Continue reading “PHP 5.5+ Secure Password Hashing”