SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2011
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    creat a users.sql for this scripts

    Guys, first I thank you for your helps.

    I have a script that I use for application authentication. In fact, the users must use their username and password to use my application; then, after authentication of username and password passed, they are allowed to use that application. I have that script, but I don't have the users.sql; so if possible, can someone create it for me from the following code?


    remauth.php

    PHP Code:

    <?php
        
    // Database info
        
    $MySQL_Host "localhost";
        
    $MySQL_User "root";
        
    $MySQL_Pass "pass";
        
    $MySQL_DB "blackops";

        function 
    ParsePost( )
        {
            
    $username '';
            
    $password '';
            
            
    $post file_get_contents"php://input" );
            
            
    $post str_replace"&"" "$post );
            
            
    sscanf$post"%s  %s"$username$password );
            
            return array( 
    'user' => $username,
                          
    'pass' => $password
                        
    );
        }
        
        function 
    mysql_fetch_full_result_array$result )
        {
            
    $table_result = array();
            
    $r 0;
            
            if( 
    $result === true )
            {
                return 
    $result;
            }
            
            if( 
    mysql_num_rows$result ) == )
            {
                return 
    $result;
            }
            
            while( 
    $row mysql_fetch_assoc$result ) )
            {
                
    $arr_row = array();
                
    $c 0;
                
                while ( 
    $c mysql_num_fields$result ) )
                {       
                    
    $col mysql_fetch_field$result$c );   
                    
    $arr_row$col -> name ] = $row$col -> name ];           
                    
    $c++;
                }   
                
                
    $table_result$r ] = $arr_row;
                
    $r++;
            }   
            
            return 
    $table_result;
        }
        
        class 
    DWAuth
        
    {
            var 
    $keys;
        
            function 
    AddDWValue$val )
            {
                
    $this->keys[] = $val;
            }
            
            function 
    GetAuthString( )
            {
                
    $result "";
                
                foreach( 
    $this->keys as $c )
                {
                    
    $result .= $c."#";
                }
                
                return 
    $result;
            }
        }
        
        class 
    DB
        
    {
            var 
    $connection;
            var 
    $started;
            
            function 
    start()
            {
                global 
    $MySQL_Host$MySQL_User$MySQL_Pass$MySQL_DB;
                
                
    $this->connection mysql_connect$MySQL_Host$MySQL_User$MySQL_Pass );
                
    mysql_select_db$MySQL_DB$this->connection );
            }
            
            function 
    query$query )
            {
                
    $result mysql_query$query$this->connection );
                
                if( 
    $result )
                {
                    return 
    mysql_fetch_full_result_array$result );
                }
                else
                {
                    return 
    $result;
                }
            }
            
            function 
    end()
            {
                
    mysql_close$this->connection );
            }
            
            function 
    isStarted()
            {
                return 
    $started;
            }
        }
        
        class 
    Login
        
    {
            
            function 
    CheckLogin$username$password )
            {
                
    $db = new DB();
                
    $db->start();
                
                
    $query "SELECT id, password, email FROM users WHERE username='".$username."' AND password='".md5$password )."';";
                
                
    $result $db->query$query );
                
                
    $db->end();
                
                if( 
    $result == false )
                    return 
    false;
                    
    fwrite($fh$result);
                    
    fclose($fh);
                    
                    
                if( 
    md5$password ) == $result][ 'password' ] )
                {
                    return array( 
    'id' => $result][ 'id' ],
                                  
    'mail' => $result][ 'email' ],
                                  
    'user' => $username
                                
    );
                }
            }
        }
        
        
    $packet = new DWAuth();
        
    $result ParsePost();
        
        if( ( empty( 
    $result'user' ] ) ) || ( empty( $result'pass' ] ) ) )
        {
            
    $packet->AddDWValue"fail" );
            
    $packet->AddDWValue"Username and/or password is empty." );
            
    $packet->AddDWValue);
            
    $packet->AddDWValue"Anonymous" );
            
    $packet->AddDWValue"anonymous@example.com" );
            
    $packet->AddDWValue);
            
            echo 
    $packet->GetAuthString();
            
            die();
        }
        
        
    $login = new Login();
        
    $result $login->CheckLogin$result'user' ], $result'pass' ] );
        
        if( 
    $result == false )
        {
            
    $packet->AddDWValue"fail" );
            
    $packet->AddDWValue"incorrect username and/or password." );
            
    $packet->AddDWValue);
            
    $packet->AddDWValue"Anonymous" );
            
    $packet->AddDWValue"anonymous@example.com" );
            
    $packet->AddDWValue);
        }
        else
        {
            
    $sessionID md5rand() );
            
    // How to make the return
            
    $packet->AddDWValue"ok" ); // fail or ok
            
    $packet->AddDWValue"Success." ); // Success or error
            
    $packet->AddDWValue$result'id' ] ); // UserID
            
    $packet->AddDWValue$result'user' ] ); // Username
            
    $packet->AddDWValue$result'mail' ] ); // email
            
    $packet->AddDWValue$sessionID ); // sessionID
            
            
    $db = new DB();
            
    $db->start();
            
            
    $query "UPDATE users SET sid='".$sessionID."' WHERE id=".$result'id' ];
            
            
    $result $db->query$query );
            
    $db->end();
        }
        
        echo 
    $packet->GetAuthString();
        
    ?>

    and check_session.php:


    PHP Code:

        
        $con 
    mysql_connect("localhost","root","pass");
        if (!
    $con)
        {
        die(
    'Could not connect: ' mysql_error());
        }
        
    mysql_select_db("blackops"$con);
        
    $result mysql_query("SELECT id FROM users WHERE sid='".$_GET'sid' ]."'");
        while(
    $row mysql_fetch_array($result))
        {
        
    $id $row['id'];
        }
        
    mysql_close($con);
        
        echo 
    '1';
        
        echo 
    ' ';
        
        echo 
    $id

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2007
    Location
    San Sebastian, Spain
    Posts
    93
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    See http://www.dbforums.com/mysql/168320...ml#post6561533 It would very difficult without going through the entire application to determine the fields needed in the users table. We could guess but this could be an endless process with something breaking elsewhere due to missing fields. As I suggested you should go back to the author of the application for the script for creating that table.


Bookmarks

Posting Permissions

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