Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-13-2011, 03:02 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
SQL Login System

This is just a basic example, it may not be the most secure but it will give you an example of how to make somthing like it.
Note: Before using for the first time insert CreateTable(); directly underneath //#CLIENTSIDE and then save, once done once delete CreateTable(); from underneath //#CLIENTSIDE

Also note this does not actually do anything if you login.
But you could easily make it into a functional login.
Please bear in mind this is my first functional SQL based script, any advice/feedback is appreciated

Things to add:
Make it so if the account already exists it wont say "Account Created". Done!
Some sort of password encryption system. In Progress!
Make it so you cannot add two accounts by changing weather the first letter is in upper-case or not. Done!

The script is attached.
Attached Files
File Type: txt LoginScript.txt (4.9 KB, 259 views)
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion

Last edited by Gunderak; 10-13-2011 at 06:10 PM..
Reply With Quote
  #2  
Old 10-13-2011, 03:54 PM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
NEVER store raw passwords in databases.

Also your data isn't even escaped properly. Use format, escape, and float or int when you make queries. I.e:

temp.query = format("SELECT username FROM Users WHERE something = '%s' OR number = %s", provided_something.escape(), float(provided_number));

Passwords should be salted and hashed before inserted into the database. For that you need 3 columns:

username, password, salt

To "register" a user:
1. Generate a random salt:
temp.salt = md5(timevar2);

2. Hash the player's provided password with the salt:
temp.password = md5(salt @ provided_password @ salt);

3. Store the hashed password and salt in the database with the username.

To "login" a user:

1. Use a select statement to retrieve the username:
temp.query = format(SELECT username, password, salt
FROM Users
WHERE username = '%s', provided_username.escape());

2. Compare the hash like this:
if (user_password == md5(salt @ provided_password @ salt)) { // Success
__________________
Quote:
Reply With Quote
  #3  
Old 10-13-2011, 04:23 PM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
Thanks for your feedback.
Before I release it on the server I will DEFINITELY make the passwords encrypted
As I said this is my first ever SQL script. sorry for the errors in it. I will post the updated version when ready.
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #4  
Old 10-13-2011, 09:07 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
Thanks for your feedback.
Before I release it on the server I will DEFINITELY make the passwords encrypted
Not encrypted, hashed. You should never be able to retrieve passwords from a database and restore them to their original form (as an interesting sidenote, Graal's support center database was leaked and resulted in 4,126 usernames, emails, and plain-text passwords being released because their passwords were recoverable (or stored as unsalted MD5 or something, not sure)).
__________________

Last edited by cbk1994; 10-13-2011 at 11:01 PM..
Reply With Quote
  #5  
Old 10-13-2011, 10:33 PM
oo_jazz_oo oo_jazz_oo is offline
Jazz teh Awesome
oo_jazz_oo's Avatar
Join Date: Jul 2006
Location: California
Posts: 596
oo_jazz_oo is a jewel in the roughoo_jazz_oo is a jewel in the rough
Send a message via MSN to oo_jazz_oo
Quote:
Originally Posted by fowlplay4 View Post
Long text...salt
Is it really necessary to add the salt onto the password, even when the password is hashed?

Since your storing the salt in the database anyways, if the database was compromised, they would be able to see the salt, then just take that away from the password and have the hashed password anyways.

I'm not arguing that you shouldn't use it, i'm asking why use it.

Edit: Nvm, I didn't notice you were using the salt inside the md5() hash...
However, I still dont see how this would make the login any more secure, since the salt is automatically added to the password on login attempt.
If you were trying random passwords, you would still only need to know the single password, and the salt would be added...
At least on say, a website, how would this add security? Since if a system was trying random password to break in, it wouldn't need to know the salt anyways...
__________________

Reply With Quote
  #6  
Old 10-13-2011, 10:55 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by oo_jazz_oo View Post
Is it really necessary to add the salt onto the password, even when the password is hashed?

Since your storing the salt in the database anyways, if the database was compromised, they would be able to see the salt, then just take that away from the password and have the hashed password anyways.

I'm not arguing that you shouldn't use it, i'm asking why use it.

Edit: Nvm, I didn't notice you were using the salt inside the md5() hash...
However, I still dont see how this would make the login any more secure, since the salt is automatically added to the password on login attempt.
If you were trying random passwords, you would still only need to know the single password, and the salt would be added...
At least on say, a website, how would this add security? Since if a system was trying random password to break in, it wouldn't need to know the salt anyways...
Salts don't protect against brute force, they protect against rainbow tables. Salts are only useful after the database has been compromised (imagine there's a SQL injection vulnerability in your website and somebody gets a copy of your users table; even if they had the code that generated the hashes, they'd have virtually no way of recovering the passwords since rainbow tables are impractical).

Quote:
Originally Posted by Wikipedia
The benefit provided by using a salted password is making a lookup table assisted dictionary attack against the stored values impractical, provided the salt is large enough. That is, an attacker would not be able to create a precomputed lookup table (i.e. a rainbow table) of hashed values (password + salt), because it would take too much space. A simple dictionary attack is still very possible, although much slower since it cannot be precomputed.
Rainbow tables get very large as the length of the original phrase (salt + password + salt) increases. An MD5 rainbow table that contains all alphanumeric inputs that are 1-8 characters is 160 GB. One with inputs 1-10 alphanumeric is 396 GB; this is the largest I could easily find online. If the salt is 10 characters, and the password is 8, that's a 28 character input. That would be one huge database.

(it's worth nothing that MD5 or SHA1 and other fast algorithms aren't recommended for password storage in the real world)
__________________
Reply With Quote
  #7  
Old 10-14-2011, 12:06 AM
Mark Sir Link Mark Sir Link is offline
Kevin Azite
Mark Sir Link's Avatar
Join Date: Sep 2005
Posts: 1,489
Mark Sir Link is just really niceMark Sir Link is just really nice
Send a message via AIM to Mark Sir Link
Quote:
Originally Posted by oo_jazz_oo View Post
if the database was compromised
in most cases within Graal, if the database is compromised than it's the fault of some staff member just looking through it.

In which case I'd be much more worried about them just intercepting the plain text of the password immediately from the client.

Last edited by Mark Sir Link; 10-14-2011 at 07:22 AM..
Reply With Quote
  #8  
Old 10-14-2011, 12:11 AM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
I've always preferred a HMAC styled approach but both have their pros/cons . In anycase, cleartext passwords are evil and even straight-hashed passwords can be reversed if it's included in a rainbow table.
Reply With Quote
  #9  
Old 10-14-2011, 12:24 AM
Emera Emera is offline
Delterian Hybrid
Emera's Avatar
Join Date: Mar 2011
Location: Newcastle Upon-Tyne
Posts: 1,704
Emera is a jewel in the roughEmera is a jewel in the rough
Loving the fail quote.
__________________
Reply With Quote
  #10  
Old 10-14-2011, 02:39 AM
Gunderak Gunderak is offline
Coder
Gunderak's Avatar
Join Date: Jun 2011
Location: Australia
Posts: 795
Gunderak is on a distinguished road
all this nerd talk confuses me further xD
__________________

Gund for president.

Remote PM {P*}x (Graal813044) from eraiphone -> Stefan: I hav 1 qustion
*Gunderak: he hav 1
*Gunderak: qustion
Reply With Quote
  #11  
Old 10-14-2011, 10:09 PM
ff7chocoboknight ff7chocoboknight is offline
Skyzer Zolderon
ff7chocoboknight's Avatar
Join Date: Dec 2006
Location: New Hampshire, United States
Posts: 725
ff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to allff7chocoboknight is a name known to all
Send a message via AIM to ff7chocoboknight Send a message via MSN to ff7chocoboknight
Quote:
Originally Posted by cbk1994 View Post
Not encrypted, hashed. You should never be able to retrieve passwords from a database and restore them to their original form (as an interesting sidenote, Graal's support center database was leaked and resulted in 4,126 usernames, emails, and plain-text passwords being released because their passwords were recoverable (or stored as unsalted MD5 or something, not sure)).
And that was a fun week.
__________________
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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

Forum Jump


All times are GMT +2. The time now is 11:30 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.