user.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. function addUser($username,$password,$email){
  6. $salt = get_sql()->escape_string(salt());
  7. $email = get_sql()->escape_string($email);
  8. $username = get_sql()->escape_string($username);
  9. $hash = get_sql()->escape_string(saltedHash($password,$salt));
  10. $res = query("INSERT INTO `users` (email,name,password,salt) VALUES ('%s','%s','%s','%s')",Array($email,$username,$hash,$salt));
  11. alog('u',mysqli_insert_id(get_sql()),'User Created');
  12. return $res;
  13. }
  14. function isUser($name){
  15. $res = query("SELECT id FROM `users` WHERE name='%s'",Array($name));
  16. return $res && $res->num_rows == 1;
  17. }
  18. function userId($name){
  19. if($user = query("SELECT id FROM `users` WHERE name='%s'",Array($name))){
  20. if($user->num_rows == 1){
  21. $user = $user->fetch_assoc();
  22. return $user['id'];
  23. }
  24. }
  25. return false;
  26. }
  27. function userObj($id){
  28. if(is_string($id)){
  29. $id = userId($id);
  30. }
  31. if($res = query("SELECT u.id,u.name,u.email,u.password,u.salt,u.key,u.last_pm_check FROM `users` AS u WHERE id=%d",Array($id))){
  32. if($res->num_rows == 1){
  33. if($user = $res->fetch_assoc()){
  34. unset($user['password']);
  35. unset($user['salt']);
  36. unset($user['key']);
  37. return $user;
  38. }
  39. }
  40. }
  41. return false;
  42. }
  43. ?>