Advertisement
kevin_neven

Untitled

Jun 13th, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. public function register($username, $password, $email, $bio, $profile_picture = NULL, $rights = 1) {
  2. $valid_email_pattern = '/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD';
  3. // src = Michael Rushton
  4. /*
  5. Feel free to use and redistribute this code. But please keep this copyright notice.
  6. */
  7.  
  8. if(self::$handler->isLoggedin() === true) {// the user is already logged in there for he can not register.
  9. $_SESSION['errorarray']["register"]["logged"] = "You mustn't be logged in";
  10. }
  11. if($password == "") {// the password is not set.
  12. $_SESSION['errorarray']["register"]["password"] = "You must chose a password";
  13. }
  14. if($username == "") {// the username is not set so he must enter it.
  15. $_SESSION['errorarray']["register"]["username"] = "You must enter a username";
  16. }
  17. if(count(
  18. Database::getInstance()->select(
  19. array(
  20. "user" => array("user_ID")
  21. ),
  22. array(
  23. array("`user_username`", "=", $username)
  24. )
  25. )->fetchAll(PDO::FETCH_ASSOC)) > 0) {
  26. $_SESSION['errorarray']["register"]["username-allowed"] = "There already is a user with this username";
  27. }
  28. if($email == "") {
  29. $_SESSION['errorarray']["register"]["email"] = "You have to enter an e-mail adress";
  30. }
  31. if(!isset($_SESSION['errorarray']["register"]["email"])){
  32. $_SESSION['errorarray']["register"]["email-valid"] = "You have to enter a valid e-mail adress";
  33. }
  34. if(preg_match($valid_email_pattern, $email) != 1){
  35.  
  36. $_SESSION['errorarray']["register"]["email-valid"] = "You have to enter an e-mail adress";
  37. }
  38. if(count($_SESSION['errorarray']["register"]) === 0){
  39. $user_array = array(
  40. "user_username" => $username,
  41. "user_password" => Cryptography::hashPassword($password),
  42. "user_email" => $email,
  43. "rights_ID" => $rights
  44. );
  45. //var_dump($profile_picture);
  46.  
  47. /* Database::getInstance()->insert(
  48. "user", $user_array
  49. );*/
  50. }
  51.  
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement