Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $username= filter_input(INPUT_POST,"userName", FILTER_SANITIZE_STRING);
- $email=filter_input(INPUT_POST,"userEmail", FILTER_VALIDATE_EMAIL);
- $password = "";
- $verifyPassword= "";
- if(isset($_POST['userpassword'])){
- $password=$_POST['userpassword'];
- }
- if(isset($_POST['verifyPassword'])){
- $verifyPassword=$_POST['verifyPassword'];
- }
- //$verifyPassword=filter_input(INPUT_POST,"verifyPassword",FILTER_SANATIZE_STRING);
- //pattern against which to check email validity
- $good_email = "[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}";
- $goodPassword = "/^(?=.*d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,255}$/";
- //if provided data is valid (email especially) and no form field has been left empty display "everything is okay"
- if(strlen($username) > 0 && strlen($email) > 0 && preg_match("/$good_email/", $email) && strlen($password) > 0 && preg_match("/$goodPassword/",$password) && strlen($verifyPassword) > 0 && $password == $verifyPassword)
- {
- $stmt1 = $dbh->prepare("SELECT userEmail FROM regularUser WHERE userEmail = :email");
- $stmt1->bindParam("email", $email) ;
- $stmt1->execute();
- $result1 = $stmt1->fetchAll(PDO::FETCH_ASSOC);
- $count = $result1->rowCount();
- if($count > 1)
- {
- echo "Email already exist";
- }
- else
- {
- $stmt = $dbh->prepare("INSERT INTO regularUser(userEmail,userName,userPassword) VALUES (:email,:name,:password)");
- $stmt->bindParam("email", $email) ;
- $stmt->bindParam("name", $username) ;
- $hash = password_hash($password, PASSWORD_BCRYPT);
- $stmt->bindParam("hash_password", $hash) ;
- $stmt->execute();
- var_dump($stmt);
- echo "success";
- }
- }
- else{
- //if message has been left empty let the user know that the name is required
- if(strlen($username) == 0){
- echo "<br/>Name is required";
- }
- //if the email is left empty let the user know that an email is required
- else if(strlen($email) == 0){
- echo "<br/>Email is required";
- }
- //if the email does not match the pattern ($good_email) let the user know that the email they have supplied is invalid
- else if(!(preg_match("/$good_email/", $email))){
- echo "<br/>Email is not valid";
- }
- else if(!(preg_match("/$goodPassword/", $password))){
- echo "<br/>Password is not valid";
- }
- else if(strlen($password) == 0){
- echo "<br/>Length of the password is not right";
- }
- else if(strlen($verifyPassword) == 0){
- echo "<br/>Password not matched";
- }
- }
Add Comment
Please, Sign In to add comment