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

Solved login plugin (more info inside)

Comments in 'Plugin Development' started by HOST, Oct 4, 2015.

  1. HOST
    Offline

    HOST Active Member

    Joined:
    Mar 15, 2015
    Posts:
    52
    Minecraft User:
    HOST
    hello fellow members
    i would like some help i want people to register on my site and i want to have the users
    to use the same login on my minecraft server , is this possible?
    what would i need to do, is there a plugin for that?

    thanks in advance!
    Last edited by a moderator: Oct 4, 2015
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    The best way to do this is using a database. Then your website and the server easily can access the data. No idea if simpleauth already supports sql.

    But in this forum you'll find more about mysql and login
    Last edited by a moderator: Oct 4, 2015
    Taha_The_Hacker likes this.
  3. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Make your website share the same database as SimpleAuth.
    You can also choose to write a DataProvider for SimpleAuth based on your database.
  4. HOST
    Offline

    HOST Active Member

    Joined:
    Mar 15, 2015
    Posts:
    52
    Minecraft User:
    HOST
    thanks both, i will try to use SimpleAuth but for now SimpleAuth is giving errors with 1.6 mc
  5. HOST
    Offline

    HOST Active Member

    Joined:
    Mar 15, 2015
    Posts:
    52
    Minecraft User:
    HOST
    i have a little problem connecting i have the database setup and login /registration works fine
    but on the site i let the database login use the simpleauth login like this

    $uau['db'] = 'simpleauth';
    $uau['table'] = 'simpleauth_players';
    $uau['id'] = 'name';
    $uau['salt'] = '';
    $uau['cms'] = 'SimpleAuth';
    $uau['cuser'] = 'name';
    $uau['cpass'] = 'hash';
    $uau['pm'] = '';
    $uau['posts'] = '';
    $uau['mail'] = 'user_email';
    $uau['ip'] = 'lastip';
    $uau['time'] = 'time';


    am i doing something wrong?
    it says invalid login when logging into the website..
  6. HOST
    Offline

    HOST Active Member

    Joined:
    Mar 15, 2015
    Posts:
    52
    Minecraft User:
    HOST
    i would kindly ask for some help on this i'm stuck hahaha
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
  8. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Don't share you database info, fools can mess with it.
  9. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    This should work if you include it as a file on your website (I assume you know basic PHP and will know to change the namespace and stuff)
    PHP:
    <?php

    namespace website;

    function 
    checkHash($str1$str2) {
        if(
    strlen($str1) != strlen($str2)) {
            return 
    false;
        } else {
            
    $res $str1 $str2;
            
    $ret 0;
            for(
    $i strlen($res) - 1$i >= 0$i--) $ret |= ord($res[$i]);
                return !
    $ret;
        }
    }

    class 
    Auth {
       
        private 
    $username;
       
        private 
    $password;

        public 
    $dbhost "host.com";

        public 
    $dbuser "root";

        public 
    $dbpword "root";

        public 
    $db "name";

        public function 
    __construct($username$password) {
            
    $this->username $username;
            
    $this->password $password;
           
            
    $this->database = new \mysqli($this->dbhost$this->dbuser$this->dbpassword$this->db3306);
            if(
    $this->database->connect_error) {
                echo(
    "Couldn't connect to Database:" $this->database->connect_error);
                return;
            }
        }

        public function 
    register($username$password) {
            if(
    $this->validUsername($username) and $this->validPassword($password)) {
                
    $this->database->query("INSERT INTO simpleauth_players
                    (name, hash)
                    VALUES
                    ('" 
    $this->database->escape_string(strtolower($username)) . "', '" $this->hash($username$password) . "')
                    "
    );
                return 
    true;
            }
            return 
    false;
        }

        public function 
    login($username$password) {
            if(
    $this->validUsername($username) and $this->validPassword($password)) {
                
    $result $this->database->query("SELECT * FROM simpleauth_players WHERE name = '" $this->database->escape_string($username). "'");
                if(
    $result instanceof \mysqli_result) {
                    
    $result->fetch_assoc();
                    
    $result->free();
                    if(isset(
    $data["name"]) and strtolower($data["name"] === $name) and isset($data["hash"]) and checkHash($data["hash"], $this->hash($username$password))) {
                        return 
    true;
                    }
                }
            }
            return 
    false;
        }

        
    //Use SimpleAuth's hashing method to make it compatible
        
    public function hash($salt$password) {
            return 
    bin2hex(hash("sha512"$password $salttrue) ^ hash("whirlpool"$salt $passwordtrue));
        }

        
    //Checks for a valid Username
        
    public function validUsername($name) {
            if(
    $name !== null and count_chars($name) >= 4) {
                return 
    true;
            }
            return 
    false;
        }

        
    //Checks for a valid Password
        
    public function validPassword($password) {
            if(
    $password !== null and count_chars($password) >= 6) {
                return 
    true;
            }
            return 
    false;
        }
    }
    To use this you will need to do:
    PHP:
    $auth = new \Auth($username$password);
    $auth->login();//or
    $auth->register();
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    It's not database info, it's SimpleAuth's Database layout or format.
  11. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    OK. Just in case.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Did you even see anything sensitive in it? :p

Share This Page

Advertisement