Advertisement
Guest User

Untitled

a guest
Jan 13th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.53 KB | None | 0 0
  1. <?php
  2. // CONNECTIONS =========================================================
  3. $host = "localhost"; //put your host here
  4. $user = 'root'; //in general is root
  5. $password = ''; //use your password here
  6. $dbname = "times_table_game"; //your database
  7. mysql_connect($host, $user, $password) or die("Cant connect into database");
  8. mysql_select_db($dbname)or die("Cant connect into database");
  9. // =============================================================================
  10. $unityHash = $_POST["myform_hash"];
  11. $phpHash = "hashcode"; // same code in here as in your Unity game
  12.  
  13. $nick = $_POST["myform_user"];
  14. $pass = md5($_POST["myform_pass"]); // md5 hashes the password
  15. $ans = md5($_POST["myform_ans"]);
  16.  
  17. if(!$nick || !$pass || !$ans)
  18. {
  19. echo "Username or password or Security Question cant be empty.";
  20. }
  21. else
  22. {
  23. if ($unityHash != $phpHash)
  24. {
  25. echo "HASH code is diferent from your game";
  26. }
  27. else
  28. {
  29. $checkuser = mysql_query("SELECT username FROM users WHERE username = '$nick'");
  30. $username_exist = mysql_num_rows($checkuser);
  31. if($username_exist > 0)
  32. {
  33. echo "I'm sorry but the username you specified has already been taken. Please pick another one.";
  34. unset($nick);
  35. exit();
  36. }
  37. if($username_exist = 0)
  38. {
  39. $query = "INSERT INTO users (username, password,security_question_ans)
  40. VALUES('$nick', '$pass','$ans')";
  41. mysql_query($query) or die(mysql_error());
  42. mysql_close();
  43. echo "You have successfully Registered";
  44.  
  45. }
  46.  
  47. }
  48. }
  49.  
  50. private var username = ""; //this is the field where the player will put the name to login
  51. private var password = ""; //this is his password
  52. private var confpass = ""; //This is for confirrming their password
  53. private var security_question_id = ""; // This is for their security question
  54. private var security_question_ans = ""; // THis is for Security answers
  55.  
  56. var formText = ""; //this field is where the messages sent by PHP script will be in
  57.  
  58. var URL = "http://localhost/FYP_PHP/ConnectionR.php"; //change for your URL
  59. var hash = "hashcode"; //change your secret code, and remember to change into the PHP file too
  60.  
  61. private var textrect = Rect (10, 150, 50, 50); //just make a GUI object rectangle
  62.  
  63. function OnGUI() {
  64. GUI.Label( Rect (60, 10, 90, 20), "Register" );
  65. GUI.Label( Rect (10, 40, 80, 20), "Username:" ); //text with Username
  66. GUI.Label( Rect (10, 70, 80, 20), "Password:" ); //text with password
  67. GUI.Label( Rect (10, 100, 70, 70), "Confirm Password: "); //text with confirm password
  68. GUI.Label( Rect (10, 135, 70, 70), "Security Question:"); //security question answer
  69. GUI.Label( Rect (10, 180,80, 20), "Answers: ");
  70. GUI.Label ( Rect (75, 150, 250, 20), "What is your mother middle name?"); // Security Question
  71.  
  72. username = GUI.TextField ( Rect (75, 40, 100, 20), username ); //here you will insert the new value to variable formNick
  73. password = GUI.TextField ( Rect (75, 70, 100, 20), password ); //same as above, but for password
  74. confpass = GUI.TextField ( Rect (75, 110, 100, 20), confpass); // to confirm password
  75. security_question_ans = GUI.TextField (Rect(75,180,150,20), security_question_ans);
  76.  
  77. if ( GUI.Button ( Rect (10, 210, 80, 20) , "Register" ) ){ //just a button
  78. Register();
  79. }
  80.  
  81.  
  82. if ( GUI.Button (Rect (100,210, 80, 20), "Back") ){
  83. Back();
  84.  
  85. }
  86.  
  87. }
  88. function Register() {
  89. var connection = new WWWForm(); //here you create a new form connection
  90. connection.AddField( "myform_hash", hash ); //add your hash code to the field myform_hash, check that this variable name is the same as in PHP file
  91. connection.AddField( "myform_user", username );
  92. connection.AddField( "myform_pass", password );
  93. connection.AddField( "myform_cpass", confpass );
  94. //connection.AddField( "myform_Sques", Security );
  95. connection.AddField( "myform_ans", security_question_ans);
  96.  
  97. var B = WWW(URL, connection); //here we create a var called 'w' and we sync with our URL and the form
  98. yield B; //we wait for the form to check the PHP file, so our game dont just hang
  99. if (B.error != null) {
  100. print(B.error); //if there is an error, tell us
  101. } else {
  102. print("Register Successful");
  103. formText = B.data; //here we return the data our PHP told us
  104. B.Dispose(); //clear our form in game
  105. Application.LoadLevel(2);
  106.  
  107. }
  108.  
  109. username = ""; //just clean our variables
  110. password = "";
  111. confpass = "";
  112. security_question_ans = "";
  113. }
  114. function Back() {
  115. Application.LoadLevel (0);
  116.  
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement