Advertisement
Guest User

Untitled

a guest
Feb 7th, 2016
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.51 KB | None | 0 0
  1. if (isset($_POST['register'])) // Lets the user register, if the name is taken, return "taken", if it's not, put it in the database and return "ok"
  2. {
  3. $username = strip_tags($_POST['regUsername']);
  4. $password = strip_tags($_POST['regPassword']);
  5. $username = stripslashes($username);
  6. $password = stripslashes($password);
  7. $password = md5($password);
  8.  
  9. $checkExist = "SELECT * FROM users WHERE username='$username'";
  10. $checkExistQ = mysqli_query($db, $checkExist);
  11.  
  12. $rows = mysqli_num_rows($checkExistQ);
  13.  
  14. if ($rows == 0) {
  15. $sql_store = "INSERT INTO users (id, username, password, money, level, xp, atk, def, hp) VALUES (NULL, '$username', '$password', 50, 1, 0, 8, 0, 100)";
  16. $sql = mysqli_query($db, $sql_store) or die(mysql_error());
  17. die("ok");
  18. } else {
  19. die("taken");
  20. }
  21. }
  22.  
  23. if (isset($_POST['login']))
  24. {
  25. $username = strip_tags($_POST['logUsername']);
  26. $password = strip_tags($_POST['logPassword']);
  27. $username = stripslashes($username);
  28. $password = stripslashes($password);
  29. $password = md5($password);
  30.  
  31. $sql = "SELECT * FROM users WHERE username='$username' LIMIT 1";
  32. $query = mysqli_query($db, $sql);
  33. $row = mysqli_fetch_array($query);
  34. $id = $row['id'];
  35. $db_password = $row['password'];
  36.  
  37. if ($db_password == $password) {
  38. die("login"."SEPERATOR".$id);
  39. }
  40. else {
  41. die("passwrong");
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement