proble in sign up code

Discussion in 'HTML & Website Design' started by brahiù, Jan 19, 2015.

  1. #1
    I have created a website when i click on register it says parse error: syntax error, unexpected end of file here is the code
    <?php




    $mysql_hostname = "localhost";mt_rand()));
    $mysql_user = "root";

    $mysql_password = "";

    $mysql_database = "cryptothrift";

    $prefix = "";
    $bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");

    mysql_select_db($mysql_database, $bd) or die("Could not select database");


    $urldecode = $_SERVER['REQUEST_URI'];

    $url1=explode("=",$urldecode);
    $page=$url1[1];

    if ($page=="register")
    {

    header('Content-Type: application/json');

    $email=$_REQUEST['email'];
    $username=$_REQUEST['username'];

    //$varpwd=mot de passe généré



    function random_readable_pwd($length=10)
    {

    // the wordlist from which the password gets generated
    // (change them as you like)
    $words = 'AbbyMallard,AbigailGabble,AbisMal,Abu,Adella,TheAgent,AgentWendyPleakley,Akela,AltheAlligator,Aladar,Aladdin,AlamedaSlim,AlanaDale,Alana,Alcmene,Alice,AmeliaGabble,AmosSlade,Amphitryon,AnastasiaTremaine,Anda,Andrina,Angelique,AngusMacBadger';

    // Split by ",":
    $words = explode(',', $words);
    if (count($words) == 0){ die('Wordlist is empty!'); }

    // Add words while password is smaller than the given length
    $pwd = '';

    while (strlen($pwd) < $length){
    $r = mt_rand(0, count($words)-1);
    $pwd .= $words[$r];
    }

    $num = mt_rand(1, 99);
    if ($length > 2){
    $pwd = substr($pwd,0,$length-strlen($num)).$num;
    } else {
    $pwd = substr($pwd, 0, $length);
    }

    $pass_length = strlen($pwd);
    $random_position = rand(0,$pass_length);

    $syms = "!@#$%^&*()-+?";
    $int = rand(0,51);

    $rand_char = $syms[$int];

    $pwd = substr_replace($pwd, $rand_char, $random_position, 0);

    return $pwd;
    }

    $password=random_readable_pwd();
    echo($password);





    echo ($password);



    //requete pour vérifier l'existance de mail



    $requeteinsertion='insert INTO users (username,password) VALUES('.$username.','.$password.')';

    if(mysql_query($requeteinsertion))
    {


    //envoi de mail qui contient le mot de passe

    $to=$email;
    $subject="registeration to crptothrift";

    $message="thank you for registering to cryptothrift your password is ".$pass;

    $headers=NULL;

    mail($to, $subject, $message, $headers);




    echo"succes";





    }
    else
    {

    echo"failure";


    }
    ?>
     
    brahiù, Jan 19, 2015 IP
  2. adamarc

    adamarc Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #2
    That should fix it ;)
     
    adamarc, Jan 19, 2015 IP
  3. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #3
    You've got a LOT of gibberish AND outdated code in there...

    $mysql_hostname = "localhost";mt_rand()));

    For example... what are you closing with all those )))? Why are you calling my_rand but not assigning it to anything? Why are you wasting so much time making "variables for nothing"?

    ... and of course to read you the riot act, this is 2015 not 2005, why are you using the insecure, deprecated and soon no to be no longer even supported mysql_ functions? You know, those giant red warning boxes in the manual waving you off from their use?

    Though I've no clue what that mess of code is even trying to accomplish -- it almost looks like a needlessly convoluted attempt at password encryption and / or auto-generation that reeks of brute-force methodology for something that could likely be done far far simpler.

    I would also REALLY advise against checking $_REQUEST for UN/PW -- since that includes $_GET and you really have NO business even THINKING about accepting passwords as getData. That's kind of a "Security, what's that?" way of doing things... though is this a AJAX handler? Don't "cheap out" on that by plugging it into the URL client-side, use POST like a good little doobie.

    I'd also suggest one-way hashing your password when putting it in the DB -- don't store them unencoded or even reversible encoded in the DB. hash('sha256', $password) good as always. That way you check them query-wise one directional; avoiding making PW's "recoverable" at all. It's just good practice to set it up so that you NEVER have ANY queries that actually pull the PW from the database -- have the engine check for a match so that the password is never a PHP variable once it's created.

    ... and even when creating it unset that variable at the earliest opportunity.
     
    deathshadow, Jan 20, 2015 IP