您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

user.php 822B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. require_once "sql.php";
  3. require_once "utils.php";
  4. function hash_password($password)
  5. {
  6. return md5($password);
  7. }
  8. function user_create()
  9. {
  10. $username = get_post("username");
  11. $password = get_post("password");
  12. if (strlen($username) < 3)
  13. error(422, "Username too short");
  14. if (database_exec("SELECT id FROM users WHERE `username` = :username",
  15. array(":username" => $username))->fetch() !== false)
  16. error(409, "Username already exists");
  17. database_exec("INSERT INTO users (`username`, `password`) ".
  18. "VALUES(:username, :password)", array(":username" => $username,
  19. ":password" => hash_password($password)));
  20. user_login($username);
  21. }
  22. function user_login($username = false )
  23. {
  24. if ($username === false)
  25. {
  26. $username = get_post("username");
  27. $password = get_post("password");
  28. }
  29. }
  30. ?>