Hi
guys i first thank you for helps.
and i have a script i use that for application authentication In fact the users must use your user name and password to use that App then after authentication of they user and pass passed they allow to use that application. and i have that script but i dont have the users.sql so if possible can someone creat it for me from the following code.

Thank you.

remauth.php:

<?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 ) == 0 )
        {
            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[ 0 ][ 'password' ] )
            {
                return array( 'id' => $result[ 0 ][ 'id' ],
                              'mail' => $result[ 0 ][ '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( 1 );
        $packet->AddDWValue( "Anonymous" );
        $packet->AddDWValue( "anonymous@example.com" );
        $packet->AddDWValue( 0 );

        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( 1 );
        $packet->AddDWValue( "Anonymous" );
        $packet->AddDWValue( "anonymous@example.com" );
        $packet->AddDWValue( 0 );
    }
    else
    {
        $sessionID = md5( rand() );
        // 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

    $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;

?>

/////////////////////
Thank you.

Recommended Answers

All 7 Replies

CREATE TABLE `users` (
  `id` bigint(20) unsigned NOT NULL auto_increment,
  `username` varchar(255) NOT NULL,
  `password` varchar(255) NOT NULL,
  `email` varchar(255) NOT NULL,
  `sid` varchar(255) default NULL,
  PRIMARY KEY  (`id`),
  UNIQUE KEY `idx_username` USING BTREE (`username`)
)

Thank you i love you :D

but i have some problem becuase i use Login System v.2.0 for manges my users and this login system is use this sql:

can it possible for you enter your posted sql to this login system sql.

#
#  dbtables.sql
#
#  Simplifies the task of creating all the database tables
#  used by the login system.
#
#  Can be run from command prompt by typing:
#
#  mysql -u yourusername -D yourdatabasename < dbtables.sql
#
#  That's with dbtables.sql in the mysql bin directory, but
#  you can just include the path to dbtables.sql and that's
#  fine too.
#
#  Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
#  Last Updated: August 13, 2004
#

#
#  Table structure for users table
#
DROP TABLE IF EXISTS users;

CREATE TABLE users (
 username varchar(30) primary key,
 password varchar(32),
 userid varchar(32),
 userlevel tinyint(1) unsigned not null,
 email varchar(50),
 timestamp int(11) unsigned not null
);


#
#  Table structure for active users table
#
DROP TABLE IF EXISTS active_users;

CREATE TABLE active_users (
 username varchar(30) primary key,
 timestamp int(11) unsigned not null
);


#
#  Table structure for active guests table
#
DROP TABLE IF EXISTS active_guests;

CREATE TABLE active_guests (
 ip varchar(15) primary key,
 timestamp int(11) unsigned not null
);


#
#  Table structure for banned users table
#
DROP TABLE IF EXISTS banned_users;

CREATE TABLE banned_users (
 username varchar(30) primary key,
 timestamp int(11) unsigned not null
);

or i have to use a simple login system :D

thank you.

Just add the missing columns from my example into the table structure of your script.

Thank you
but i don have enough nowledge about that may i pleas an request form you that you do it for me.

Thank you.

Trying yourself will make you learn quicker, than just copying will.

ok i try but in your sql cod the PRIMARY key is id :

PRIMARY KEY (id),

and in this cod the username is primary:

username varchar(30) primary key,

and in your example the id like that:

id bigint(20) unsigned NOT NULL auto_increment,

but in this code :

userid varchar(32),

also and what is it in you example :

UNIQUE KEY idx_username USING BTREE (username)

?!!!

That depends on what you want to use. The last key in my example is to ensure uniqueness of the username, since I use an id as primary key.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.