Standard Username / Password Authentication (Simpleuser Authentication)
Standard Username / Password Authentication (SimpleUser)
If you are looking for a standard username / password or email / password authentication then the YGN / Player.io paltform with it’s SimpleUser system should be sufficient for your needs. In my other post, New User Registration (simple user), we looked at how to register a new simple user. In this post I'm going to assume that you have at least one user registered already, and will use that account to test authentication here.
So in order to test this authentication realistically we will have need a flash movie clip that has two input fields. It will have a TextField for inputting the username, one for inputting the password, and a button to submit the credentials for authentication. I have provided this in the downloadable source files for this tutorial.
How It Works
So let's say you are a user going through and logging in. You enter username or email address in the first field and the password in the second field. Then you click the submit button. Then back in the code the interesting stuff happens in the handler for the submit button click. I like to have a separate singleton class (if you don't know what that is check out the post on singletons) to handle all of the player.io logic. Here's an example of how your submitted by handler might look:
First we take what has been entered into text fields and save it into strings. Then we pass the strings into a player I know controller function that will handle the actual authentication.
---
Below you can see an example of the logging function that you might find in the player.io controller class.
---
The mystical ‘authenticate’ method handles the mystical method handles most of the work. It’s a static method in the Playerio class. This method can be a bit intimidating because it takes bunch of parameters, but let's go through them here and see that it’s really not that bad.
1) Stage – the stage is the first parameter that you pass into the authenticate function. I like to save a reference to the stage in the model class as soon as the application starts up. Sometimes saving this with the datatype of Stage can cause exceptions to be throw however, so I like to give it the type Object and then cast it to stage when I need to, which is what we are doing here.
2) Game ID – this is the unique ID given to your game by YGN. You can get this ID by logging into your yahoo games account, going to ‘my games’, and clicking on the name of your game.
3) Connection ID – This parameter allows you to choose an Authentication scheme form potentially multiple different ones you can set up for your game. To see the connection id’s you can log into your YGN account and choose your game. Then on the left side navigation menu go to Settings. In the middle of the page you'll see a table titled Connections. This allows you to have multiple connections which really just correspond to multiple different types of authentication. For example, you might want one for regular username password users and one for guest users that automatically accepts any string as a username (You can then generate the guest username as something like “Guest” + _randomInteger). The name of the connection (the words in blue letters) in the table here is the connection ID that you pass into the authenticate method.
4) Auth Dictionary – This is a dictionary object that contains the credentials used to log the user in. The keys for the dictionary must be “username”, “email”, and “password” (although email is optional). According to the Yahoo documentation, it will first check the username & password combination. If that works then the user is logged in and you have your client object. If that does not work then the player.io systems will check the email & password combination. If this works, then you’re in. If not then the pop-up should display an error message prompting the user to try to enter his / her credentials again. Being able to type either your username or your email into the first box when logging in is something users usually love and find very intuitive so it’s great that YGN has conveniently set up SimpleUser authentication to make it so easy for us developers to implement. Also, you should not have collisions with usernames and email addresses because the @ symbol is not allowed in usernames.
5) Player insight – This parameter is for player insight. Player insight is another service built into the player.io platform. It gives you more statistics about each user individually and some overall information about all your users as a group. For more information on this see my other post, using player insight. For now we can just leave this parameter as null.
6) Authentication Success Handler Function - This is the function to be called on successful authentication. In this function you will magically get an object of type Client. This is the key to all the multiplayer services and functions for the rest of the game as long as the user is logged in.
7) Authentication Failure Function – This is a functionality called when there is an error authenticating. Not only will this function help you in debugging problems when it gets triggered unexpectedly, but it will also give you vital feedback that you can display to the user. The function takes in a PlayerIoError object, and you can use this to give feedback to the user. For example if no username or email exists for the one they entered you will get this in an error message. You can just display error.message, or if you want to customize your error messages a bit more you can make a switch statement with error ID and display your own error messages.
Well, that's all for this post. I hope simple user authentication is simple enough for you to understand exhalation point now get out there and start making someone screens.
If you are looking for a standard username / password or email / password authentication then the YGN / Player.io paltform with it’s SimpleUser system should be sufficient for your needs. In my other post, New User Registration (simple user), we looked at how to register a new simple user. In this post I'm going to assume that you have at least one user registered already, and will use that account to test authentication here.
So in order to test this authentication realistically we will have need a flash movie clip that has two input fields. It will have a TextField for inputting the username, one for inputting the password, and a button to submit the credentials for authentication. I have provided this in the downloadable source files for this tutorial.
How It Works
So let's say you are a user going through and logging in. You enter username or email address in the first field and the password in the second field. Then you click the submit button. Then back in the code the interesting stuff happens in the handler for the submit button click. I like to have a separate singleton class (if you don't know what that is check out the post on singletons) to handle all of the player.io logic. Here's an example of how your submitted by handler might look:
First we take what has been entered into text fields and save it into strings. Then we pass the strings into a player I know controller function that will handle the actual authentication.
---
Below you can see an example of the logging function that you might find in the player.io controller class.
---
The mystical ‘authenticate’ method handles the mystical method handles most of the work. It’s a static method in the Playerio class. This method can be a bit intimidating because it takes bunch of parameters, but let's go through them here and see that it’s really not that bad.
1) Stage – the stage is the first parameter that you pass into the authenticate function. I like to save a reference to the stage in the model class as soon as the application starts up. Sometimes saving this with the datatype of Stage can cause exceptions to be throw however, so I like to give it the type Object and then cast it to stage when I need to, which is what we are doing here.
2) Game ID – this is the unique ID given to your game by YGN. You can get this ID by logging into your yahoo games account, going to ‘my games’, and clicking on the name of your game.
3) Connection ID – This parameter allows you to choose an Authentication scheme form potentially multiple different ones you can set up for your game. To see the connection id’s you can log into your YGN account and choose your game. Then on the left side navigation menu go to Settings. In the middle of the page you'll see a table titled Connections. This allows you to have multiple connections which really just correspond to multiple different types of authentication. For example, you might want one for regular username password users and one for guest users that automatically accepts any string as a username (You can then generate the guest username as something like “Guest” + _randomInteger). The name of the connection (the words in blue letters) in the table here is the connection ID that you pass into the authenticate method.
4) Auth Dictionary – This is a dictionary object that contains the credentials used to log the user in. The keys for the dictionary must be “username”, “email”, and “password” (although email is optional). According to the Yahoo documentation, it will first check the username & password combination. If that works then the user is logged in and you have your client object. If that does not work then the player.io systems will check the email & password combination. If this works, then you’re in. If not then the pop-up should display an error message prompting the user to try to enter his / her credentials again. Being able to type either your username or your email into the first box when logging in is something users usually love and find very intuitive so it’s great that YGN has conveniently set up SimpleUser authentication to make it so easy for us developers to implement. Also, you should not have collisions with usernames and email addresses because the @ symbol is not allowed in usernames.
5) Player insight – This parameter is for player insight. Player insight is another service built into the player.io platform. It gives you more statistics about each user individually and some overall information about all your users as a group. For more information on this see my other post, using player insight. For now we can just leave this parameter as null.
6) Authentication Success Handler Function - This is the function to be called on successful authentication. In this function you will magically get an object of type Client. This is the key to all the multiplayer services and functions for the rest of the game as long as the user is logged in.
7) Authentication Failure Function – This is a functionality called when there is an error authenticating. Not only will this function help you in debugging problems when it gets triggered unexpectedly, but it will also give you vital feedback that you can display to the user. The function takes in a PlayerIoError object, and you can use this to give feedback to the user. For example if no username or email exists for the one they entered you will get this in an error message. You can just display error.message, or if you want to customize your error messages a bit more you can make a switch statement with error ID and display your own error messages.
Well, that's all for this post. I hope simple user authentication is simple enough for you to understand exhalation point now get out there and start making someone screens.