User Tag List

Page 2 of 3 FirstFirst 1 2 3 LastLast
Results 11 to 20 of 22

Thread: Connecting to a MySQL database....?

  1. #11
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jul 2006
    Location
    Pittsburgh, PA, USA
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    I DID IT! If you're curious as to what the code is.....
    Code:
    <?php
    
    $name = $_GET['name'];
    $userpassword = $_GET['userpassword'];
    
    $service = "localhost";
    $username = "pauliuko";
    $password = "sdfsfsf";
    $database = "pauliuko_games";
    
    mysql_connect($service, $username, $password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $result = mysql_query("SELECT * FROM users WHERE name='$name' and password='$userpassword'") or die(mysql_error());
    $row = mysql_fetch_array( $result );
    
    if($row=='') echo "0";
    else echo "1";
    
    ?>

  2. #12
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    You shouldn't store passwords directly in the database, you should store a hash of the password, eg md5
    I believe php has an md5() function for this.

    You're also trusting user input without escaping it. What happens if someone uses a ' in their password in your code? How about "' or '1'='1" as the password?
    Answer: You end up with this query:
    "SELECT * FROM users WHERE name='hacker' and password='' or '1'='1'"
    and the "or '1'='1'" is always true, so it will allow login, with whatever username they want, even an admin account (or even if that username's not in the database at all!)

    EDIT: Also make sure that the username you're using to connect to the database from php only has permission to do what it needs to (Add records and read records, maybe modify records). Whatever you do don't log in to your database from php with an account that has "drop database" permissions, or a hacker will be able to destroy your entire database with ease.

  3. #13
    Clicker Fusion 2.5 DeveloperAndroid Export ModuleHTML5 Export ModuleSWF Export ModuleInstall Creator ProPatch Maker
    Fusion 2.5 (Steam)Fusion 2.5 Developer (Steam)Fusion 2.5+ DLC (Steam)Android Export Module (Steam)HTML5 Export Module (Steam)iOS Export Module (Steam)Universal Windows Platform Export Module (Steam)
    DJFuego's Avatar
    Join Date
    Jul 2006
    Location
    UK
    Posts
    1,416
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    Can you post the revised code with the MD5 hashing of the password.

  4. #14
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    $userpassword = md5($_GET['userpassword']);

  5. #15
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export Module
    DavidN's Avatar
    Join Date
    Jun 2006
    Location
    Boston, MA, USA
    Posts
    4,044
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    Good to know you got the query worked out - PHP has many ways to do the same thing, and mysql_fetch_array() and mysql_query() both do roughly the same job.

    The original problem when you were using mysql_query() as in my tutorial, as far as I can see, was that you were calling the query string "$get" when you were setting it up, and then running a query called "$query", which didn't exist.

  6. #16
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jul 2006
    Location
    Pittsburgh, PA, USA
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    Dynasoft, the reason that I didn't add the code in to check that the username and password are alphanumeric is because I want to do the least amount of php coding as possible. I literally just learned what I had to in order to do what I did and I don't want to have to learn any more. I have a perfectly working alphanumeric check in MMF2 that I programmed instead.

    Are you saying that I should submit the password as a MD5 hash and then store it as the real password, or store it as a MD5 hash as well? I really don't think it's necessary. I don't expect my users to be saving anything really important.

  7. #17
    No Products Registered

    Join Date
    Jul 2006
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    Why not use
    PHP Code:
    mysql_num_rows() 
    ?

    For example:

    PHP Code:
    $myQuery mysql_query("SELECT * FROM $table WHERE userName = '$userName' AND userPassword = '$userPassword'");
    return 
    mysql_num_rows($myQuery); 

  8. #18
    Clicker Multimedia Fusion 2 Developer

    Join Date
    Jun 2006
    Location
    Darlington, UK
    Posts
    3,298
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    Quote Originally Posted by pinacoladaxb
    Dynasoft, the reason that I didn't add the code in to check that the username and password are alphanumeric is because I want to do the least amount of php coding as possible. I literally just learned what I had to in order to do what I did and I don't want to have to learn any more. I have a perfectly working alphanumeric check in MMF2 that I programmed instead.
    It's not hard, just call mysql_escape_string() on the variables to prevent the injection attack. It's one function

    Quote Originally Posted by pinacoladaxb
    Are you saying that I should submit the password as a MD5 hash and then store it as the real password, or store it as a MD5 hash as well? I really don't think it's necessary. I don't expect my users to be saving anything really important.
    Store it as md5. It's bad security to store actual passwords, because users tend to use the same password for everything, and they don't take too kindly to someone knowing it. Again, it's not hard to do, php has an md5() function you can use

    EDIT: Like this, I think:
    Code:
    <?php
    
    $name = $_GET['name'];
    $userpassword = md5($_GET['userpassword']);
    
    $service = "localhost";
    $username = "pauliuko";
    $password = "sdfsfsf";
    $database = "pauliuko_games";
    
    mysql_connect($service, $username, $password);
    @mysql_select_db($database) or die( "Unable to select database");
    
    $result = mysql_query("SELECT * FROM users WHERE name='".mysql_escape_string($name)."' and password='".mysql_escape_string($userpassword)."'") or die(mysql_error());
    $row = mysql_fetch_array( $result );
    
    if($row=='') echo "0";
    else echo "1";
    
    ?>

  9. #19
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jul 2006
    Location
    Pittsburgh, PA, USA
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    OK. I'll take your advice.

  10. #20
    Clicker Multimedia Fusion 2 DeveloperSWF Export Module

    Join Date
    Jul 2006
    Location
    Pittsburgh, PA, USA
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Connecting to a MySQL database....?

    I did it! It was easier than I thought. I'll use your advice for the injection attack thing as well. Thanks for your help!

    EDIT: Oops. I didn't see that you gave me the code. I did it on my own. :blush:

Page 2 of 3 FirstFirst 1 2 3 LastLast

Similar Threads

  1. Connecting to a database via flash and mobile apps
    By FrankyAsh in forum SWF/Flash Export Module Version 2.0
    Replies: 2
    Last Post: 17th January 2011, 10:21 AM
  2. ASP.NET to access a mySQL database from MMF2?
    By RGBreality in forum Multimedia Fusion 2 - Technical Support
    Replies: 1
    Last Post: 15th September 2010, 08:26 PM
  3. Hi-score and mysql database
    By videogiochi in forum Multimedia Fusion 2 - Technical Support
    Replies: 16
    Last Post: 14th July 2010, 04:10 PM
  4. [REQUEST] MySQL database
    By Dynamite in forum Extension Development
    Replies: 2
    Last Post: 10th March 2010, 05:08 AM
  5. Database: Connecting to a database over internet
    By Ham in forum Multimedia Fusion 2 - Technical Support
    Replies: 2
    Last Post: 9th March 2010, 11:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •