WTF is Token Authentication ?

So your working on a web app and you realize you want to allow them have accounts and login and out. To accomplish this, you can use a number of different things, or just use what ever your web framework (ASP.NET MVC, Express, Rails, and etc) of choose does.

Or you can use this thing called “Token Authentication”. Now what it is, exactly what it sounds like, its just a token you pass between your client (browser) and server to validate your request.

You might be thinking well that sounds okay but what stops someone from capturing your token and pretending to be you. Or what would stop someone from making a fake token ?

JWT (JSON Web Token) stops all those things. It is self contained and can hold a variety of different information. Its structure can be broken down into three parts:

  1. Header (can be decoded by anyone)
    • Contains what algorithm was used to encrypt it
  2. Payload (can be decoded by anyone)
    • The info (user name, id, expiry date and etc) stored inside the token
    • Got to be careful with what type of info you put in here
  3. Signature
    • What the server uses to actually validate the token.
    • Generated by doing the following :
    • HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), secret)
    • That “secret” part is what is used to generate the signature, and lives on your server.

     

So that is why:

  1. A person cannot capture your token and infinity use it , since we can specify a expiry date.
  2. A person cannot make a fake one, since we hash the token with a secret that only lives on the server

A few cool side features of using a JWT is that the server does not need to validate the user by interacting with the data store. Which may be a big deal if you want to have a high performance application. The other cool feature is that since you have reduced your authentication method to a JWT, it gives you a lot more flexibility in what ( maybe a mobile app ) can interact with your API.

WTF is an Extension ?

Have you every want to modify your car ? Well if you have then you already know the basics of what a extension is. Since you modify something that someone else has made (maybe you also made it too, but thats okay).

OR have you ever been in a situation where, you are working on something. And you thought “maybe I should write a new class to extend this other class, that way I add to the functionality”. You could do that, “could” being the keyword there. OR you could just use Extentions 🙂

Extensions let you add new functionality to existing classes, structs, enumerations, or protocols. All you have to do is extended them.

WTF is a closure ? 

Your going about your normal programming life. Everything is fine, your using functions and classes and variables, and etc. And you’ll be thinking “I got this programming thing pretty much in the bag”

But then you see “it” what “it” is your not sure. Its something coming out the side of your function … OMG is looks like another function. A function against a function ???

We all know what a function is, it is just piece of code that we can use in different places. It some times takes in varables and spits them out. This is all “normal”, however what if I told you that you could return a function from a function ? Or even add a function as a input value ? Pretty crazy right ?

Some of you out there might be thinking, “why would you need this ? stop making things soo complicated !” Well if you want your applications to run asynchronously, your gonna wanna use closures when ever you do something that takes alot of time.

So the use case would go something like this:You wanna log someone in, and execute something else as soon as it finishs, without freezing up the UI (in a iOS app).

Instead of doing it the standard way of writing the code that needs to be executed right after the method call. You can just pass the login function, another function to execute once done.

The in depth code will come in part two.

Hope you found the theory behind it easy to understand 😅

Project – Pins

Pins is a hyper causal game I made awhile ago. It revolves around trying to get all your pins stuck into a circling object above. The challenge comes in getting all the pins to stick, with out touching any of the other pins.

Here it is on both the iTunes and Google Play Store:

Here is a link to the Github repo: https://github.com/RedGhoul/Pins

Here are a few of the screen shoots:

 

Project – The Event Horizon

This is a game I have in development. It is an atmospheric horror FPS, with rogue lite elements. I am using Unity to make it. Whats funny is that I hate scary games, and have almost never played one, but now I am making one lol. Below is what I have done so far.

And here is link to the github repo: https://github.com/RedGhoul/FPS_4

Neural Network Types

I have been working on my capstone project for the last little bit. It involves using neural networks to solve the problem of segmenting medical images.

Here is a little of what I have learned. I think I am going to start doing a series about this. Mainly cause Machine learning is easier than it seems, and the more people that realize that, the more innovation that will happen 😁

* You wanna have a good understanding of a basic generic Neural networks, before reading on.

So lets get on with it. There are basically a couple of different types of neural network types, such as Generative Adversarial Networks (GAN), Convolutional Networks (CNN), and Recurrent Networks (RNN). Each have their own area and application where they work best. However they all generally use the same principles.

In GANs one part of the NN, is called the generator. This generator generates new data instances, while the other part, the discriminator, evaluates them for authenticity. The discriminator decides whether each instance of data it reviews belongs to the actual training dataset or not. The goal of the discriminator, when shown an instance from the real-world, is to recognize it as authentic.

Generalized Flow of GAN events as follows: The generator takes in random numbers and returns an image. The generated image is fed into the discriminator alongside a stream of images taken from the actual dataset. The discriminator then takes in both real and fake images and returns probabilities, a number between 0 and 1, with 1 representing a prediction of authenticity and 0 representing fake. Then it enters a double feedback loop. Where the discriminator is in a feedback loop with the ground truth, and the generator is in a feedback loop with the discriminator.

GAN_FlowChart

CNNs for SIS are similar to ordinary GANs in the sense that they are made up of two main parts. The first part is known as the encoder, which is responsible for extracting the features of the image. And the second part is known as the decoder, which is responsible for decoding the image.

CNN_FlowChart

The encoding part of CNNs are stacks of Convolutional (C), Activation (A), and Pooling (P) Layers. In the convolutional layer, filters are passed along the image taking dot products to create feature maps. These result of this gets passed through an activation layer. If the first CA layer gets done too many times the feature maps start to degrade, therefor P layers are used. These P layers average out the values in the feature map, which helps perceive the keys features. Most CNN architectures have several CAP stacks before getting put into the decoding aspect of the CNN.

CNN_Filter

The decoding part of the NN goes through the inverse operations of the encoder. Since by the time the feature maps reach the decoder they have been significantly compressed. The CAP layers in the decoding portion go through the process of deconvolution and up sampling using max pooling.

RNNs are a type of NNs where connections between units form a directed graph along a sequence. This allows it to exhibit dynamic temporal behavior for a time sequence. Unlike feedforward neural networks, RNNs can use their internal state (memory) to process sequences of inputs. This makes them applicable to tasks such as unsegmented, connected handwriting recognition or speech recognition.

Recurrent networks are distinguished from feedforward networks by that feedback loop connected to their past decisions, ingesting their own outputs moment after moment as input. It is often said that recurrent networks have memory. Adding memory to neural networks has a purpose: There is information in the sequence itself, and recurrent nets use it to perform tasks that feedforward networks can’t.

That sequential information is preserved in the recurrent network’s hidden state, which manages to span many time steps as it cascades forward to affect the processing of each new example. It is finding correlations between events separated by many moments, and these correlations are called “long-term dependencies”. This is because an event downstream in time depends upon, and is a function of, one or more events that came before. One way to think about RNNs is this: they are a way to share weights over time.