Guest User

Untitled

a guest
Dec 2nd, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. <?php
  2. // Attempts to create account
  3. // Params: $username = string, username of account to be created (not escaped)
  4. // $password = string, password of account to be created (not escaped)
  5. // $email = string, email of account to be created (not escaped)
  6. // Return: -1 = database error
  7. // 1 = account craeted
  8. // 0 = account already exists
  9. function createAccount($username, $password, $email)
  10. {
  11. $mysql_conn = mysql_connect(&#039;127.0.0.1&#039;, &#039;website_realmd&#039;, &#039;PASSWORD&#039;);
  12. if (!$mysql_conn)
  13. return -1;
  14.  
  15. if (!mysql_select_db(&#039;realmd&#039;, $mysql_conn))
  16. return -1;
  17.  
  18. if ($query = mysql_query(&#039;SELECT 1 FROM `account` WHERE `username`=\&#039;&#039; . mysql_real_escape_string($username) . &#039;\&#039; LIMIT 1&#039;, $mysql_conn))
  19. {
  20. if (mysql_num_rows($query))
  21. return 0;
  22. }
  23.  
  24. mysql_query(&#039;INSERT INTO `account` (username, sha_pass_hash, email, expansion) VALUES (\&#039;&#039; . mysql_real_escape_string(strtoupper($username)) . &#039;\&#039;,
  25. \&#039;&#039; . sha1(strtoupper($username . &#039;:&#039; . $password)) . &#039;\&#039;, \&#039;&#039; . strtoupper(mysql_real_escape_string($email)) . &#039;\&#039;, 2)&#039;, $mysql_conn);
  26.  
  27. return 1;
  28. }
Add Comment
Please, Sign In to add comment