SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 20/06/2012, 08:03 PM   #1
newbienoob
High-roller
 
newbienoob's Avatar
 
Join Date: Jan 2012
Location: Follow the moaning coming from your parents' bedroom
Posts: 1,580
Reputation: 252
Default Login/Register system [YINI+Whirlpool]

Intro

This is my first tutorial on this forums. I've seen many people having a problem with the other YINI tutorials. So in this tutorial, I will teach you how to make your own login/register system for your server using YINI and Whirlpool without having any problem.

Requirements

Before you start, make sure you have all this required plugin/include
YSI - By Y_Less
Whirpool -By Y_Less

Lets Get Started

1)Includes
pawn Code:
#include <a_samp>
#include <YSI\y_ini>  //If you have installed YSI, then you shouldn't have any problem

2)Defines
pawn Code:
#define dregister 2011 //Defining register dialog so it won't mixed up with the other dialogs
#define dlogin 2012 //Defining login dialog so it won't mixed up with the other dialogs
#define UserPath "Users/%s.ini" /*Will define user's account path. In this case, we will save it in Scriptfiles/Users. So create a file inside of your Scriptfiles folder called Users

3)Whirlpool
pawn Code:
native WP_Hash(buffer[],len,const str[]); // Whirlpool native, add it at the top of your script under includes

4)Enum
Enum. What they actually are? <-- Click
pawn Code:
//We will create an enum to store player's data.
enum PlayerInfo
{
    Pass[129], //User's password
    Adminlevel, //User's admin level
    VIPlevel, //User's vip level
    Money, //User's money
    Scores, //User's scores
    Kills, //User's kills
    Deaths //User's deaths
}
new pInfo[MAX_PLAYERS][PlayerInfo]; /*This will create a new variable so we can later use it to saving/loading user's info.*/

5)Stock
pawn Code:
stock Path(playerid) //Will create a new stock so we can easily use it later to load/save user's data in user's path
{
    new str[128],name[MAX_PLAYER_NAME];
    GetPlayerName(playerid,name,sizeof(name));
    format(str,sizeof(str),UserPath,name);
    return str;
}
6)Function
pawn Code:
forward loadaccount_user(playerid, name[], value[]); //forwarding a new function to load user's data

7)Loading User's Account
pawn Code:
//Now we will use our own function that we have created above
public loadaccount_user(playerid, name[], value[])
{
    INI_String("Password", pInfo[playerid][Pass],129); /*we will use INI_String to load user's password.
    ("Password",.. will load user's password inside of user's path. 'pInfo[playerid][Pass]',...We have defined our user's variable above called, pInfo. Now it's time to use it here to load user's password. '129',... 129 is a length of a hashed user's password. Whirlpool will hash 128 characters + NULL*/

    INI_Int("AdminLevel",pInfo[playerid][Adminlevel]);/*We will use INI_Int to load user's admin level. INI_Int stands for INI_Integer. This load an admin level. */
    INI_Int("VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
    INI_Int("Money",pInfo[playerid][Money]); //As explained above
    INI_Int("Scores",pInfo[playerid][Scores]);//As explained above
    INI_Int("Kills",pInfo[playerid][Kills]);//As explained above
    INI_Int("Deaths",pInfo[playerid][Deaths]);//As explained above
    return 1;
}

8.)OnPlayerConnect
pawn Code:
/*OnPlayerConnect will be called when players is connected to your server. So now we will need to show a register or login dialog*/
public OnPlayerConnect(playerid)
{
    new name[MAX_PLAYER_NAME]; //Making a new variable called 'name'. name[MAX_PLAYER_NAME] is created so we can use it to get player's name.
    GetPlayerName(playerid,name,sizeof(name)); //Get player's name
    if(fexist(Path(playerid))) /* Check if the connected user is registered or not. fexist stands for file exist. So if file exist in the files(Path(playerid)),*/
    {// then
        INI_ParseFile(Path(playerid),"loadaccount_%s", .bExtra = true, .extra = playerid); //Will load user's data using INI_Parsefile.
        ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account","Login","Quit");/*A dialog with input style will appear so you can insert your password to login.*/
    }
    else //If the connected user is not registered,
    {//then we will 'force' him to register :)
        ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.","Register","Quit");
        return 1;
    }
    return 1;
}

9)OnDialogResponse
pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == dregister) //If dialog id is a register dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            if(!strlen(inputtext)) //If they didn't enter any password
            {// then we will tell to them to enter the password to register
                ShowPlayerDialog(playerid,dregister,DIALOG_STYLE_INPUT,"Register","Welcome! This account is not registered.\nEnter your own password to create a new account.\nPlease enter the password!","Register","Quit");
                return 1;
            }
            //If they have entered a correct password for his/her account...
            new hashpass[129]; //Now we will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext);//We will use whirlpool to hash their inputted text
            new INI:file = INI_Open(Path(playerid)); // we will open a new file for them to save their account inside of Scriptfiles/Users folder
            INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
            INI_WriteString(file,"Password",hashpass);//This will write a hashed password into user's account
            INI_WriteInt(file,"AdminLevel",0); //Write an integer inside of user's account called "AdminLevel". We will set his level to 0 after he registered.
            INI_WriteInt(file,"VIPLevel",0);//As explained above
            INI_WriteInt(file,"Money",0);//Write an integer inside of user's account called "Money". We will set their money to 0 after he registered
            INI_WriteInt(file,"Scores",0);//Write an integer inside of user's account called "Scores". We will set their score to 0 after he registered
            INI_WriteInt(file,"Kills",0);//As explained above
            INI_WriteInt(file,"Deaths",0);//As explained above
            INI_Close(file);//Now after we've done saving their data, we now need to close the file
            SendClientMessage(playerid,-1,"You have been successfully registered");//Tell to them that they have successfully registered a new account
            return 1;
        }
    }
    if(dialogid == dlogin) //If dialog id is a login dialog
    {//then
        if(!response) return Kick(playerid); //If they clicked the second button "Quit", we will kick them.
        if(response) //if they clicked the first button "Register"
        {//then
            new hashpass[129]; //Will create a new variable to hash his/her password
            WP_Hash(hashpass,sizeof(hashpass),inputtext); //Will hash inputted password
            if(!strcmp(hashpass, pInfo[playerid][Pass], false)) //If they have insert their correct password
            {//then
                INI_ParseFile(Path(playerid),"loadaccount_%s",.bExtra = true, .extra = playerid);//We will load his account's data from user's path
                SetPlayerScore(playerid,pInfo[playerid][Scores]);//We will get their score inside of his user's account and we will set it here
                GivePlayerMoney(playerid,pInfo[playerid][Money]);//As explained above
                SendClientMessage(playerid,-1,"Welcome back! You have successfully logged in");//Tell them that they've successfully logged in
            }
            else //If they've entered an incorrect password
            {//then
                ShowPlayerDialog(playerid,dlogin,DIALOG_STYLE_INPUT,"Login","Welcome back. This account is registered. \nInsert your password to login to your account.\nIncorrect password!","Login","Quit");//We will tell to them that they've entered an incorrect password
                return 1;
            }
        }
    }
    return 1;
}

10)OnPlayerDisconnect
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    //Same as OnDialogResponse, we will save their stats inside of their user's account
        new INI:file = INI_Open(Path(playerid)); //will open their file
        INI_SetTag(file,"Player's Data");//We will set a tag inside of user's account called "Player's Data"
        INI_WriteInt(file,"AdminLevel",pInfo[playerid][Adminlevel]); //If you've set his/her admin level, then his/her admin level will be saved inside of his/her account
        INI_WriteInt(file,"VIPLevel",pInfo[playerid][VIPlevel]);//As explained above
        INI_WriteInt(file,"Money",GetPlayerMoney(playerid));//We will save his money inside of his account
        INI_WriteInt(file,"Scores",GetPlayerScore(playerid));//We will save his score inside of his account
        INI_WriteInt(file,"Kills",pInfo[playerid][Kills]);//As explained above
        INI_WriteInt(file,"Deaths",pInfo[playerid][Deaths]);//As explained above
        INI_Close(file);//Now after we've done saving their data, we now need to close the file
    return 1;
}
11)OnPlayerDeath
pawn Code:
public OnPlayerDeath(playerid, killerid, reason)
{
    pInfo[killerid][Kills]++;//Will give 1 kill to killer and it will be saved inside of his/her account
    pInfo[playerid][Deaths]++;//Will give 1 death each time they die and it will be saved inside of his/her account
    return 1;
}

12)server.cfg
Inside of your server.cfg, add this line
Code:
plugins Whirlpool
Congratulations you have successfully created your own login/register system with YINI.

Previews
http://imgffs.com/i/rFexV.png
http://imgffs.com/i/tXUq.png
http://imgffs.com/i/cxNhE.png
http://imgffs.com/i/YXn30.png
http://imgffs.com/i/Exck9.png
http://imgffs.com/i/lDXAm.png

Credits
newbienoob - For making this tutorial
Y_Less - YINI and Whirlpool
iPLEOMAX - For his Enumerators tutorial

NOTE1: There might be some typo in this tutorial. I was too tired. It's 4am right now -_-
NOTE2: If there's any problem/mistake in this tutorial, please let me know.
NOTE3: You can ask here if you have any question/problem.
NOTE4: Make sure you reset all variables under OnPlayer(Dis)Connect so player's stats won't mix up.

Last edited by newbienoob; 22/08/2013 at 02:35 AM.
newbienoob is offline   Reply With Quote
Old 20/06/2012, 08:46 PM   #2
Mr.Fames
Huge Clucker
 
Join Date: Oct 2011
Posts: 350
Reputation: 24
Default Re: Login/Register system [YINI+Whirlpool]

good job.
Mr.Fames is offline   Reply With Quote
Old 20/06/2012, 08:53 PM   #3
Mimic
Huge Clucker
 
Mimic's Avatar
 
Join Date: Jul 2010
Posts: 220
Reputation: 6
Default Re: Login/Register system [YINI+Whirlpool]

I don't mean any disrespect buddy but...

http://forum.sa-mp.com/showthread.php?t=273088

I don't think there is any need for this tutorial when there is a perfectly good one already. Other than my comment, good job.
__________________
Coming soon
Mimic is offline   Reply With Quote
Old 21/06/2012, 06:01 AM   #4
Mr.Fames
Huge Clucker
 
Join Date: Oct 2011
Posts: 350
Reputation: 24
Default Re: Login/Register system [YINI+Whirlpool]

Quote:
Originally Posted by Mimic View Post
I don't mean any disrespect buddy but...

http://forum.sa-mp.com/showthread.php?t=273088

I don't think there is any need for this tutorial when there is a perfectly good one already. Other than my comment, good job.
That tutorial doesn't explain the usage of whirlpool
Mr.Fames is offline   Reply With Quote
Old 21/06/2012, 06:04 AM   #5
SkL_MD
Big Clucker
 
SkL_MD's Avatar
 
Join Date: May 2012
Location: Romania
Posts: 147
Reputation: 1
Default Re: Login/Register system [YINI+Whirlpool]

Good work!
SkL_MD is offline   Reply With Quote
Old 21/06/2012, 08:05 AM   #6
newbienoob
High-roller
 
newbienoob's Avatar
 
Join Date: Jan 2012
Location: Follow the moaning coming from your parents' bedroom
Posts: 1,580
Reputation: 252
Default Re: Login/Register system [YINI+Whirlpool]

Quote:
Originally Posted by Mimic View Post
I don't mean any disrespect buddy but...

http://forum.sa-mp.com/showthread.php?t=273088

I don't think there is any need for this tutorial when there is a perfectly good one already. Other than my comment, good job.
Have you tried that tutorial? Or that 'Full package'? I can't even login. I've seen many people having a problem with that tutorial. So I made this new one. Plus, that tutorial is using udb_hash to hash password. I'm using whirlpool to hash password which more safer than udb_hash.

Quote:
Originally Posted by Y_Less View Post
And don't use udb_hash - it is a very insecure hash algorithm. You need something like Whirlpool.

Even worse than udb_hash though is plain text - ALWAYS encrypt passwords! Would you want other people to be able to read your passwords?
__________________
#leftsamp
newbienoob is offline   Reply With Quote
Old 21/06/2012, 12:41 PM   #7
Mimic
Huge Clucker
 
Mimic's Avatar
 
Join Date: Jul 2010
Posts: 220
Reputation: 6
Default Re: Login/Register system [YINI+Whirlpool]

I have tried that tutorial actually, it worked fine for me. I didn't mean any disrespect, you seem like you've took offence?
__________________
Coming soon
Mimic is offline   Reply With Quote
Old 21/06/2012, 01:22 PM   #8
newbienoob
High-roller
 
newbienoob's Avatar
 
Join Date: Jan 2012
Location: Follow the moaning coming from your parents' bedroom
Posts: 1,580
Reputation: 252
Default Re: Login/Register system [YINI+Whirlpool]

Quote:
Originally Posted by Mimic View Post
I have tried that tutorial actually, it worked fine for me. I didn't mean any disrespect, you seem like you've took offence?
Nahh, and thanks for your comment.
__________________
#leftsamp
newbienoob is offline   Reply With Quote
Old 21/06/2012, 01:29 PM   #9
Jonny5
Gangsta
 
Join Date: Mar 2012
Location: Mi, USA
Posts: 935
Reputation: 146
Default Re: Login/Register system [YINI+Whirlpool]

good work noobienoob

one thing i would bring to users attention is salting the pass words also.
That is if your aim was really to improve security. This will help guard against
rainbow or dictionary attacks.


@ the link to kush's tut,
I actually have done that one when i first started and had no problems.


my personal thoughts are INI files are to be used for
Settings, and a database should be used for data.

either way your code is improving everyday so keep it up noobienoob!

here's a tutorial on salting http://forum.sa-mp.com/showthread.php?t=350664
encase you don't know about it.
__________________
If your topic says "REP+", I ignore it.

If you haven't tried it I suggest you do so.
Pawn PlayGround By Slice!

Last edited by Jonny5; 21/06/2012 at 02:01 PM.
Jonny5 is offline   Reply With Quote
Old 21/06/2012, 02:18 PM   #10
ReneG
High-roller
 
Join Date: Oct 2011
Location: Sublime Text 2
Posts: 2,005
Reputation: 333
Default Re: Login/Register system [YINI+Whirlpool]

Not bad at all. Good to see you are using Whirlpool, as said above, you are improving. Keep it up.
ReneG is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] [TUT] Register & login in dialog [Whirlpool & y_ini] System64 Tutorials 66 19/05/2014 05:49 AM
[FilterScript] [FS]Level System for RolePlay + Register/Login System AlexSAMP Filterscripts 24 10/02/2013 12:35 PM
the best login/register system without admin system and show in dialog misho1 Help Archive 2 06/05/2011 12:24 AM
where can i download an admin system and an login and register system dendudes123 Help Archive 3 19/06/2010 06:13 PM
Register/Login System Adam199 Help Archive 6 25/12/2009 07:14 PM


All times are GMT. The time now is 09:53 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.