Guest User

Untitled

a guest
Mar 26th, 2018
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. $username= filter_input(INPUT_POST,"userName", FILTER_SANITIZE_STRING);
  2. $email=filter_input(INPUT_POST,"userEmail", FILTER_VALIDATE_EMAIL);
  3. $password = "";
  4. $verifyPassword= "";
  5. if(isset($_POST['userpassword'])){
  6. $password=$_POST['userpassword'];
  7. }
  8. if(isset($_POST['verifyPassword'])){
  9. $verifyPassword=$_POST['verifyPassword'];
  10. }
  11. //$verifyPassword=filter_input(INPUT_POST,"verifyPassword",FILTER_SANATIZE_STRING);
  12.  
  13. //pattern against which to check email validity
  14. $good_email = "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}";
  15. $goodPassword = "/^(?=.*d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,255}$/";
  16.  
  17. //if provided data is valid (email especially) and no form field has been left empty display "everything is okay"
  18. if(strlen($username) > 0 && strlen($email) > 0 && preg_match("/$good_email/", $email) && strlen($password) > 0 && preg_match("/$goodPassword/",$password) && strlen($verifyPassword) > 0 && $password == $verifyPassword)
  19. {
  20. $stmt1 = $dbh->prepare("SELECT userEmail FROM regularUser WHERE userEmail = :email");
  21. $stmt1->bindParam("email", $email) ;
  22. $stmt1->execute();
  23. $result1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
  24. $count = $result1->rowCount();
  25. if($count > 1)
  26. {
  27. echo "Email already exist";
  28. }
  29. else
  30. {
  31. $stmt = $dbh->prepare("INSERT INTO regularUser(userEmail,userName,userPassword) VALUES (:email,:name,:password)");
  32. $stmt->bindParam("email", $email) ;
  33. $stmt->bindParam("name", $username) ;
  34. $hash = password_hash($password, PASSWORD_BCRYPT);
  35. $stmt->bindParam("hash_password", $hash) ;
  36. $stmt->execute();
  37. var_dump($stmt);
  38. echo "success";
  39. }
  40. }
  41. else{
  42.  
  43. //if message has been left empty let the user know that the name is required
  44. if(strlen($username) == 0){
  45. echo "<br/>Name is required";
  46. }
  47. //if the email is left empty let the user know that an email is required
  48. else if(strlen($email) == 0){
  49. echo "<br/>Email is required";
  50. }
  51. //if the email does not match the pattern ($good_email) let the user know that the email they have supplied is invalid
  52. else if(!(preg_match("/$good_email/", $email))){
  53. echo "<br/>Email is not valid";
  54. }
  55. else if(!(preg_match("/$goodPassword/", $password))){
  56. echo "<br/>Password is not valid";
  57. }
  58. else if(strlen($password) == 0){
  59. echo "<br/>Length of the password is not right";
  60. }
  61. else if(strlen($verifyPassword) == 0){
  62. echo "<br/>Password not matched";
  63. }
  64. }
Add Comment
Please, Sign In to add comment