user.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. require_once(realpath(dirname(__FILE__)).'/config.php');
  3. require_once(PATH_PHP.'database.php');
  4. require_once(PATH_PHP.'security.php');
  5. $mysqli = $GLOBALS['mysqli'];
  6. function addUser($username,$password,$email){
  7. global $mysqli;
  8. $salt = $mysqli->escape_string(salt());
  9. $email = $mysqli->escape_string($email);
  10. $username = $mysqli->escape_string($username);
  11. $hash = $mysqli->escape_string(saltedHash($password,$salt));
  12. return query("INSERT INTO `users` (email,name,password,salt) VALUES ('%s','%s','%s','%s')",Array($email,$username,$hash,$salt));
  13. }
  14. function isUser($name){
  15. if(query("SELECT id FROM `users` WHERE name='%s'",Array($name))){
  16. return true;
  17. }else{
  18. return false;
  19. }
  20. }
  21. function userId($name){
  22. if($user = query("SELECT id FROM `users` WHERE name='%s'",Array($name))){
  23. $user = $user->fetch_assoc();
  24. return $user['id'];
  25. }else{
  26. return false;
  27. }
  28. }
  29. function userObj($id){
  30. if(is_string($id)){
  31. $id = userId($id);
  32. }
  33. if($result = query("SELECT * FROM `users` WHERE id='%d'",Array($id))){
  34. return $result->fetch_assoc();
  35. }else{
  36. return false;
  37. }
  38. }
  39. ?>