I am trying to build a website with login system. i have read this stuff in the web. But i find it difficult to put them together. and i think i am missing a lots of important things, like security.
- mysqli
- verify email
- prepared statement (i have no idea what its ><)
- is there any security risk otherthan injection in the code below?
I am a self-learn programmer (just started coding several month, please help ><)
- i do not know OOP and PDO, so plesae use procedural format T.T
- do not know much about security
- This is not a project, i would like to publish it. So there must be good security.
- please help to improve it, thanks a lot!!!
am i asking to many question??
<?php
if(isset($_POST['signup-name']) and isset($_POST['signup-password-1']) and isset($_POST['signup-password-2']) and isset($_POST['signup-email-1']) and isset($_POST['signup-email-2']) and isset($_POST['signup-country']) and isset( $_POST['recaptcha_challenge_field']) and isset( $_POST['recaptcha_response_field'])){
if(!empty($_POST['signup-name']) and !empty($_POST['signup-password-1']) and !empty($_POST['signup-password-2']) and !empty($_POST['signup-email-1']) and !empty($_POST['signup-email-2']) and !empty($_POST['signup-country']) and !empty( $_POST['recaptcha_challenge_field']) and !empty( $_POST['recaptcha_response_field'])){
//echo"ok1";
$username = $_POST['signup-name'];
$email1 = $_POST['signup-password-1'];
$email2 = $_POST['signup-password-2'];
$password1 = $_POST['signup-email-1'];
$password2 = $_POST['signup-email-2'];
$country = $_POST['signup-country'];
$recaptcha_challenge_field = $_POST['recaptcha_challenge_field'];
$recaptcha_response_field = $_POST['recaptcha_response_field'];
if($email1==$email2 and $password1==$password2){
include 'db_info.php';
$connect = mysqli_connect("localhost", $db_uusseerrss, $db_ppwwdd) or die(mysql_error("Unable to select database"));
$username = mysqli_real_escape_string($connect, $username);
$email1 = mysqli_real_escape_string($connect, $email1);
$password1 = mysqli_real_escape_string($connect, $password1);
$country = mysqli_real_escape_string($connect, $username);
$bcrypt_option = array('cost'=>12);
$hashed_password = password_hash($password1, PASSWORD_BCRYPT,$bcrypt_option);
echo $hashed_password;
$query = "INSERT INTO user_info (`username`, `email`, `password`, 'country') VALUES( ?, ?, ?, ?)";
echo "ok3";
if ($stmt = mysqli_prepare($connect, $query) ) {
$stmt->bind_param("ssss", $username, $email1, $hashed_password, $country );
$stmt->execute();
echo "ok4";
//redirect to main page
headr(....)
}
}
}
}else{
}
?>