Author Topic: Hash password, not working in classes  (Read 1993 times)

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Hash password, not working in classes
« on: May 04, 2016, 03:20:06 am »
This really bugged me and had me currious as to what is the issues,. Finnaly I removed the hashing of passwords to see what was wrong and nothing was wrong. Its using hashing algorithms in a class.
I try to keep functions out of commands. Does any one have any ideas?
This is not a fix script etc more of how should I do it? hopefully not in the command system.


This is just a play script of mine

Hashes  :P


Code: [Select]
class PlayerClass
{
// ------------------------------------------------------------------- //
IP = "0.0.0.0";
Cash = 0;
Bank = 0;
Kills = 0;
Deaths = 0;
Level = 0;
Password = null;
Logged = false;
// ------------------------------------------------------------------- //
constructor( player )
{
IP = Accounts.Get( player + " IP" );
        Cash = Accounts.Get( player + " Cash" );
        Bank = Accounts.Get( player + " Bank" );
        Kills = Accounts.Get( player + " Kills" );
        Deaths = Accounts.Get( player + " Deaths" );
        Level = Accounts.Get( player + " Level" );
Password = Accounts.Get( player + " Password" );
Logged = false;
}

function Join( player )
{
    if( Level == 0 )
            {
MessagePlayer( "Please register to play.", player );
MessagePlayer( "Register with /register <password>", player );
    }
    else if ( Password )
    {
    // If they are registered, ask for them to login
    if ( Level >= 1 )
    {
MessagePlayer( "Login before spawning! /login <password>", player );
    }
    }
    else
            {
MessagePlayer( "Please login to play.", player );
MessagePlayer( "Login with /login <password>", player );
    }
}
        function Register( player, text )
{    
    if ( Level >= 1 )
    {
        MessagePlayer( "Error - You are already registered.", player );
        return 1;
    }
    else
    {
         // Otherwise they have logged in succesfully!
         Accounts.Add( player.Name + " Password", text );
         Accounts.Add( player.Name + " Level", 1 );
         Accounts.Add( player.Name + " IP", player.IP );
         Accounts.Add( player.Name + " GOTO", "off" );

         // Then we will add their kills/deaths and cash/bank
         Accounts.Add( player.Name + " Cash", 0 );
                 Accounts.Add( player.Name + " Bank", 0 );
                 Accounts.Add( player.Name + " Kills", 0 );
                 Accounts.Add( player.Name + " Deaths", 0 );
 
         // Then finally log that player in
         Account[ player.ID ].Logged = true;
         MessagePlayer( "To login to this account type: /login <password>", player );
         MessagePlayer( "You have successfully registered with us!", player );

         // And save the hash files
         SaveHashes();
    }
        }
        function LoginPlayer( player, text )
        {       
           if ( Level == 0 )
           {
                  // Player hasn't registered so tell them to do so
          MessagePlayer( "// Error: You do not have an account, register with /register <password>", player );
          return 1;
           }
 
           if ( Account[ player.ID ].Logged == true )
           {
                  // Player has already logged in
                  MessagePlayer( "// Error: You are already logged in to your account.", player );
          return 1;
           }

           if ( text != Password )
           { 
                  // Player has entered wrong password
          MessagePlayer( "Error - Invalid Password.", player ); 
          return 1;
           }
           else
   {
                   // Otherwise they have logged in succesfully!
                   Account[ player.ID ].Logged = true;
                   Account[ player.ID ].Cash = Accounts.Get( player.Name + " Cash" );
                   Account[ player.ID ].Bank = Accounts.Get( player.Name + " Bank" );
                   Account[ player.ID ].Kills = Accounts.Get( player.Name + " Kills" );
                   Account[ player.ID ].Deaths = Accounts.Get( player.Name + " Deaths" );
                   Account[ player.ID ].Level = Accounts.Get( player.Name + " Level" );
             
          player.Cash = Account[ player.ID ].Cash;
 
                  MessagePlayer( "You have successfully logged in!", player );
   }
        }
}

Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: Hash password, not working in classes
« Reply #1 on: May 04, 2016, 03:17:39 pm »
you can add functions to a class, however I believe they use the local scope of the class, so if you need anything global then you'll probably have to add a double colon before whatever it is you need to use (i.e. ::FindVehicle ).

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Hash password, not working in classes
« Reply #2 on: May 04, 2016, 03:31:08 pm »
THANKS!!! I will re add support for hashing passwords and see what happens




Tested,. Does not encrypt passwords.

« Last Edit: May 04, 2016, 03:43:17 pm by Mötley »

Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: Hash password, not working in classes
« Reply #3 on: May 04, 2016, 04:08:42 pm »
I don't see anything wrong in that line. In classes is a bit hard to find a error, use // until disappears.
« Last Edit: May 04, 2016, 05:15:40 pm by Ankris »

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Hash password, not working in classes
« Reply #4 on: May 04, 2016, 04:29:06 pm »
The error in general is MD5[Hashing of passwords] I guess I should give it up and put these functions in a command. make the encrypted text transfer over to the class functions.
« Last Edit: May 04, 2016, 05:04:48 pm by Mötley »

Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: Hash password, not working in classes
« Reply #5 on: May 04, 2016, 04:46:20 pm »
The error in general is MD5[Hashing of passwords] I guess I should give it up and put these functions in a command. make the encrypted text transfer over to the class functions.

MD5 was broken by a chinese guy. It's recommeded at least SHA1 or even better SHA256

Code: [Select]
::SHA1(password.tostring());
« Last Edit: May 04, 2016, 05:17:15 pm by Ankris »

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Hash password, not working in classes
« Reply #6 on: May 04, 2016, 04:59:44 pm »
Yes I plan to not use MD5, It is just when scripting its really simple to just type MD5 as a text

I plan to use maybe WHIRLPOOL + Salt, If anything either SHA1, or WHIRLPOOL,


Ankris

  • Full Member
  • ***
  • Posts: 110
  • Karma: +29/-44
    • View Profile
Re: Hash password, not working in classes
« Reply #7 on: May 04, 2016, 05:17:03 pm »
Code: [Select]
::SHA1(password.tostring());

Should fix the instance error (I had this error before)

Motley

  • Full Member
  • ***
  • Posts: 252
  • Karma: +32/-34
    • View Profile
Re: Hash password, not working in classes
« Reply #8 on: May 05, 2016, 10:12:59 pm »
Ankris question

It seems it is very useful to add certain functions in side of the constructor/class ..

Reasons of why

Less locals and in general it's easier to script. Any good fair warnings as to scripting alot here ?


*I just removed the old post to refresh with this one.



(Old post)



FIXED THANKS!!!

This was just a test script i don't intend to create exploits like cash levels etc

Code: [Select]
class PlayerClass
{
// ------------------------------------------------------------------- //
IP = "0.0.0.0";
Cash = 0;
Bank = 0;
Kills = 0;
Deaths = 0;
Level = 0;
Password = null;
Logged = false;
// ------------------------------------------------------------------- //
constructor( player )
{
IP = Accounts.Get( player + " IP" );
    Cash = Accounts.Get( player + " Cash" );
    Bank = Accounts.Get( player + " Bank" );
    Kills = Accounts.Get( player + " Kills" );
    Deaths = Accounts.Get( player + " Deaths" );
    Level = Accounts.Get( player + " Level" );
Password = Accounts.Get( player + " Password" );
Logged = false;
}

function Join( player )
{
if( !Level ){
::MessagePlayer( "Register before spawning! /login <password>", player );
}
    else if ( Password )
    {
    // If they are registered, ask for them to login
    if ( Level >= 1 )
    {
    ::MessagePlayer( "Login before spawning! /login <password>", player );
    }
    }
else{
   ::MessagePlayer( "Login before spawning! /login <password>", player );
}
}
// This function is used to register a player with the server
    // First we will add that players main account information
    function Register( player, text )
{    
    if ( Level >= 1 )
    {
        ::MessagePlayer( "Error - You are already registered.", player );
        return 1;
    }
    else
    {
         // Otherwise they have logged in succesfully!
         Accounts.Add( player.Name + " Password", ::SHA1(text) );
         Accounts.Add( player.Name + " Level", 1 );
         Accounts.Add( player.Name + " IP", player.IP );
         Accounts.Add( player.Name + " GOTO", "off" );

         // Then we will add their kills/deaths and cash/bank
         Accounts.Add( player.Name + " Cash", 0 );
                 Accounts.Add( player.Name + " Bank", 0 );
                 Accounts.Add( player.Name + " Kills", 0 );
                 Accounts.Add( player.Name + " Deaths", 0 );
 
         // Then finally log that player in
         Account[ player.ID ].Logged = true;
         ::MessagePlayer( "To login to this account type: /login <password>", player );
         ::MessagePlayer( "You have successfully registered with us!", player );

         // And save the hash files
         SaveHashes();
    }
}
    function LoginPlayer( player, text )
    {       
           if ( Level == 0 )
           {
              // Player hasn't registered so tell them to do so
          ::MessagePlayer( "// Error: You do not have an account, register with /register <password>", player );
          return 1;
           }
 
           if ( Account[ player.ID ].Logged == true )
           {
              // Player has already logged in
              ::MessagePlayer( "// Error: You are already logged in to your account.", player );
          return 1;
           }

   if ( ::SHA1(text) != Password )
           { 
              // Player has entered wrong password
          ::MessagePlayer( "Error - Invalid Password.", player ); 
          return 1;
           }
           else
       {
              // Otherwise they have logged in succesfully!
              Account[ player.ID ].Logged = true;
              Account[ player.ID ].Cash = Accounts.Get( player.Name + " Cash" );
              Account[ player.ID ].Bank = Accounts.Get( player.Name + " Bank" );
              Account[ player.ID ].Kills = Accounts.Get( player.Name + " Kills" );
              Account[ player.ID ].Deaths = Accounts.Get( player.Name + " Deaths" );
              Account[ player.ID ].Level = Accounts.Get( player.Name + " Level" );
             
  player.Cash = Account[ player.ID ].Cash;
 
              ::MessagePlayer( "You have successfully logged in!", player );
       }
}
}
« Last Edit: May 05, 2016, 10:15:35 pm by Mötley »

 

© Liberty Unleashed Team.