Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. <?php
  2. require_once("config.php");
  3. if(isset($_POST['register'])) {
  4. $username = htmlentities($_POST['username'], ENT_QUOTES);
  5. $usernamel = strtolower($username);
  6. $password = htmlentities($_POST['password'], ENT_QUOTES);
  7. $password_hashed = password_hash($password, PASSWORD_BCRYPT);
  8. $email = htmlentities($_POST['email'], ENT_QUOTES);
  9. $ip = $_SERVER['REMOTE_ADDR'];
  10. $time = date("Y-m-d");
  11.  
  12. $stmt = $db->prepare("SELECT * FROM users WHERE username = :username");
  13. $stmt->execute(array(':username' => $username));
  14. $row = $stmt->fetch();
  15.  
  16. if($row['username'] == $username){
  17. die(header("Location: error.php"));
  18. exit;
  19. }
  20.  
  21. if($username == ""){
  22. die(header("Location: error.php"));
  23. exit;
  24. }
  25.  
  26. if($password == ""){
  27. die(header("Location: error.php"));
  28. exit;
  29. }
  30.  
  31. if($email == ""){
  32. die(header("Location: error.php"));
  33. exit;
  34. }
  35.  
  36. if($email == ""){
  37. die(header("Location: error.php"));
  38. exit;
  39. }
  40. if (strlen($username) < 10 && preg_match('/[^a-z0-9]+/i', $username) < 1) {
  41. if (strlen($password) > 8) {
  42. $stmt = $db->prepare("INSERT INTO users (username, usernamel, password, email, ip, date) VALUES (:username, :usernamel, :password, :email, :ip, :date)");
  43. $stmt->execute(array(':username' => $username, ':usernamel' => $usernamel, ':password' => $password_hashed, ':email' => $email, ':ip' => $ip, ':date' => $time));
  44. die(header("Location: index.php"));
  45. exit;
  46. } else {
  47. echo "Password needs to be higher than 8.";
  48. exit;
  49. }
  50. } else {
  51. echo "Username needs to be lower than 10 and cant contains specialchars (!@^*& etc)";
  52. exit;
  53. }
  54. }
  55. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement