[MOD]mybb register user

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • [MOD]mybb register user

      this is a snipped used to create a user in a mybb-forum(v1.4 - 1.8 for other versions i don't know) when he registers in the game
      insert in includes\pages\login\ShowVertifyPage.class.php after line 116 (PlayerUtil::sendMessage($userID, 1, $senderName, 1, $subject, $message, TIMESTAMP);)


      PHP Source Code: includes\pages\login\ShowVertifyPage.class.php

      1. //--------------user im forum registrieren----------------------------------------
      2. function forum_registeruser($username_in, $password_in, $email_in, $usergroup_in){
      3. $servernameo = "server ip or localhost"; //<--
      4. $usernameo = "username"; //<--
      5. $passwordo = "password"; //<--
      6. try {
      7. $connect = new PDO("mysql:host=$servernameo;dbname=dbname", $usernameo, $passwordo);//<--(dbname)
      8. // set the PDO error mode to exception
      9. $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
      10. echo "Connected successfully";
      11. }
      12. catch(PDOException $e)
      13. {
      14. echo "Connection failed: " . $e->getMessage();
      15. }
      16. //test if user exists
      17. $queryo="SELECT username FROM mybb_users WHERE username='".$username_in."'";//<--use the prefix of your mybb installation
      18. $checkexistence = $connect->query($queryo);
      19. $exists=false;
      20. $counter=0;
      21. while($rowso = $checkexistence->fetch(PDO::FETCH_BOTH)){
      22. extract($rowso);
      23. if($username==NULL){
      24. $exists=false;
      25. }else{
      26. $exists=true;
      27. }
      28. }
      29. //create user
      30. if($exists==false){
      31. $salto=random_str('8');
      32. $password_hasho=salt_password($password_in, $salto);
      33. $login_keyo=generate_loginkey();
      34. $statementmant = $connect->prepare("INSERT INTO mybb_users (username, password, salt, loginkey, email, usergroup)
      35. VALUES (:username_in, :password_hasho, :salto, :login_keyo, :email_in, :usergroup_in)");//<--use the prefix of your mybb installation
      36. $insertuser = $statementmant->execute(array(
      37. ":username_in" => $username_in,
      38. ":password_hasho" => $password_hasho,
      39. ":salto" => $salto,
      40. ":login_keyo" => $login_keyo,
      41. ":email_in" => $email_in,
      42. ":usergroup_in" => $usergroup_in
      43. ));
      44. //echo('User successfully registered.');
      45. }else{
      46. //echo('User already exists.');
      47. }
      48. }
      49. function random_str($length="8")
      50. {
      51. $set = array("a","A","b","B","c","C","d","D","e","E","f","F","g","G","h","H","i","I","j","J","k","K","l","L","m","M","n","N","o","O","p","P","q","Q","r","R","s","S","t","T","u","U","v","V","w","W","x","X","y","Y","z","Z","1","2","3","4","5","6","7","8","9");
      52. $str = '';
      53. for($i = 1; $i <= $length; ++$i)
      54. {
      55. $ch = mt_rand(0, count($set)-1);
      56. $str .= $set[$ch];
      57. }
      58. return $str;
      59. }
      60. function salt_password($passwordo, $salto)
      61. {
      62. return md5(md5($salto).md5($passwordo));
      63. }
      64. function generate_loginkey()
      65. {
      66. return random_str(50);
      67. }
      68. forum_registeruser($userData['userName'], $userData['password'] , $userData['email'], '2');
      69. //------------------------------------------------------
      Display All
      replace the filds where you find a comment that looks like this: //<--
      the original script can be found here community.mybb.com/archive/
      it was written in 2008 so i had to replace dbconnection with pdo.
      but still it's running flawlessly.