Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Server Website Register?

Comments in 'Plugin Development' started by Legoboy0215, May 4, 2015.

Thread Status:
Not open for further replies.
  1. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Hello, I need some help with my server website.
    1. A website to ONLY register accounts. (I have a website, but I do not know how to play with the MySQL stuff from SimpleAuth.
    2. Manage all the accounts. (Again, the MySQL and phpmyadmin stuff.)
    I know I can use html forms and send it to a php file to process, but I do not know how to write in php! Also, I think I also need to access the SimpleAuth MySQL database. How do I do that?
    Thanks for the help!
    CraftYourBukkit likes this.
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    This seems like a pretty complicated project. I would recommend to learn PHP or (probably best) hire a developer.
  3. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ok, then how can set my own MySQL database for SimpleAuth?
  4. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
  5. DALTONTASTIC
    Offline

    DALTONTASTIC New Member

    Joined:
    Apr 27, 2015
    Posts:
    6
    Minecraft User:
    DALTONTASTIC
    I can help you out with logins, but when it comes to registrations I never integrated that directly on my site. I find that only allowing registrations in-game cuts down on spam.

    Anyhow you are going to make a file called session.php (This will need to be included on every page you want people to be logged into to see)

    PHP:
    <?php
    // Establishing Connection with Server by passing server_name, user_id and password as a parameter
    $connection mysql_connect("host""user""password");
    // Selecting Database
    $db mysql_select_db("database"$connection);
    session_start();// Starting Session
    // Storing Session
    $user_check=$_SESSION['login_user'];
    // SQL Query To Fetch Complete Information Of User
    $ses_sql=mysql_query("select name from tablename where name='$user_check'"$connection);
    $row mysql_fetch_assoc($ses_sql);
    $login_session =$row['name'];
    if(!isset(
    $login_session)){
    mysql_close($connection); // Closing Connection
    header('Location: login.php'); // Redirecting To Home Page
    }
    ?>
    Then you are going to create a file called authenticate.php (This handles the logins)

    PHP:
    <?php
    session_start
    (); // Starting Session
    $error=''// Variable To Store Error Message
    if (isset($_POST['submit'])) {
    if (empty(
    $_POST['username']) || empty($_POST['password'])) {
    $error "UNABLE TO PROCESS YOUR REQUEST. CHECK YOUR PASSWORD.";
    }
    else
    {
    // Define $username and $password
    $username=$_POST['username'];
    $password=$_POST['password'];
    // Establishing Connection with Server by passing server_name, user_id and password as a parameter
    $connection mysql_connect("host""user""password");
    // To protect MySQL injection for Security purpose
    $username stripslashes($username);
    $password stripslashes($password);
    $username mysql_real_escape_string($username);
    $password mysql_real_escape_string($password);
    // Selecting Database
    $db mysql_select_db("database"$connection);

    function 
    hashME($player$password) {
        return 
    bin2hex(hash("sha512"$password strtolower($player), true) ^ hash("whirlpool"strtolower($player) . $passwordtrue));
    }

    $password1 hashME($username$password);
    // SQL query to fetch information of registerd users and finds user match.
    $query mysql_query("select * from tablename where hash='$password1' AND name='$username'"$connection);
    $rows mysql_num_rows($query);
    if (
    $rows == 1) {
    $_SESSION['login_user']=$username// Initializing Session
    header("location: account.php"); // Redirecting To Other Page
    } else {
    $error "UNABLE TO PROCESS YOUR REQUEST. CHECK YOUR PASSWORD.";
    }
    mysql_close($connection); // Closing Connection
    }
    }
    ?>
    Okay here's the fun part! This is the login page! I named mine login.php :)

    HTML:
    <?php
       include('authenticate.php');
    
       if(isset($_SESSION['login_user'])){
       header("location: page-to-redirect-to-after-logging-in.php");
       }
       ?>
    <head>
       <title>LOGIN</title>
       <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    </head>
    <body>
       <div class="col-md-6">
          <h3>LOGIN</h3>
          <form action="" id="material" method="post">
             <?php
                if(empty($error)){
                }
                else {
                echo '<div class="alert alert-danger">';
                echo $error;
                echo '</div>';
                }
                ?>
             <div class="group">
                <input id="name" type="text" name="username" placeholder="USERNAME" autocomplete="off">
                <input id="password" type="password" name="password" placeholder="PASSWORD">
             </div>
             <center><input name="submit" type="submit" value="LOGIN" class="load-more"></a></center>
       </div>
       </form>
       </div>
       </div>
       <div class="col-md-6">
          <h3>THIS IS A BOOTSTRAP TEMPLATE</h3>
          <div id="material">
             <h2>SOOOOO</h2>
             WRITE SOMETHING INFORMATIVE HERE.
             <BR>
          </div>
       </div>
       <BR>
       <BR>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js">
    </body>
    </html>
    If you tried you could probably tweak this into a functioning registration page, but here's a good start.
    Last edited: May 5, 2015
  6. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    How do you get a MySQL server to connect to SimpleAuth, I cant get it to work :(
    Please Help!
  7. DALTONTASTIC
    Offline

    DALTONTASTIC New Member

    Joined:
    Apr 27, 2015
    Posts:
    6
    Minecraft User:
    DALTONTASTIC
    Do you currently have a MySQL instance running? This is my config.yml I've used for SimpleAuth in the past. Just interchange the values.

    Code:
    dataProvider: mysql
    
    #For MySQL:
    dataProviderSettings:
    host: "IP"
    port: 3306
    user: "user"
    password: "password"
    database: "database"
    
    #dataProviderSettings: []
    
    #If enabled, existing logged-in accounts won't be kicked if a new player joins with the same name
    forceSingleSession: true
    
    #Sets the minimum amount of characters to be used when registering a new account
    minPasswordLength: 8
    
    #If enabled, accounts that are using the same IP when logging in again will be automatically authenticated
    authenticateByLastIP: false
    
    #If enabled, will set all the permissions for simleauth.command.register to false
    disableRegister: false
    
    #If enabled, will set all the permissions for simleauth.command.login to false
    disableLogin: false
    
    #Number of seconds to wait for a player to be authenticated. If false, disables the timeout
    #TODO
    authenticateTimeout: 120
  8. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    If you look on page 16 of the SimpleAuth thread, I have tried many things, can I pm you the login credentials so you can set it up?
  9. DALTONTASTIC
    Offline

    DALTONTASTIC New Member

    Joined:
    Apr 27, 2015
    Posts:
    6
    Minecraft User:
    DALTONTASTIC
    Hm I guess so. Keep in mind that by default MySQL doesn't allow external connections.
  10. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    I went into the my.cnf, (it looked different then the first time, which almost worked but I deleted it:mad:) and allowed connecting from everything and it still did not work. :(
  11. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Alright, I will make a quick server and send you the credentials, OK?
  12. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Stop going off topic. If you need help with a different subject, create a new thread.
  13. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    You should try using MySQLi, it has a lot of new useful features like an object-oriented interface, support for prepared statements etc.
  14. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
  15. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Ok Thanks! I will try it so if there are any problems I will ask you via PM
  16. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    In addition (since this is in the Plugin Development forum), I would like to point out that the mysql extension doesn't (necessarily) exist in PocketMine-distributed PHP binaries.
    Legoboy0215 likes this.
  17. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,724
    Minecraft User:
    Legoboy0215
    Umm.... Do I need to set the MySQL database?
Thread Status:
Not open for further replies.

Share This Page

Advertisement