- Home /
Login authentication on Unity 5 with php using xampp, and mysqli
i am trying to figure out what the best way is to handle login authentication security wise. in my php code, it handles when a username exists in the database, and if the password is correct, it will display message "Login successful", but there isn't any sort of validation whether the user is successfully logged in, it just displays the message. here's my php code
//connection to db $conn = new mysqli($server_hostname, $server_username, $server_password, $db_name);
//check sqli connection
if (mysqli_connect_errno()){
echo "Failed to connect to DB: ".mysqli_connect_error();
}
//login post variables
$user_username = mysqli_real_escape_string($conn, $_POST["usernamePost"]);
$user_password = mysqli_real_escape_string($conn, $_POST["passwordPost"]);
//check is password is correct
$check_password = "SELECT password FROM users WHERE username = '$user_username'";
$result = mysqli_query($conn, $check_password);
//check empty field
if (empty($user_username) || empty($user_password)){
echo "This field is required";
}
//only one unique username should be found
else if (mysqli_num_rows($result) == 1){
while ($row = mysqli_fetch_assoc($result)){
if($row['password'] == md5($user_password)){
echo "Login successful";
}
else{
echo "Incorrect password";
}
}
}
else{
echo "Username is not found";
}
inside unity, when login button is pressed, if the user enters wrong password or username, it just displays the message saying that there is an error without any sort of security mechanism. same as when a user is successfully logged in, it just echo "Login successful". what i want to do is when a user is successfully logged in, it will validate that the user is logged in, and bring up the database for that user only. i'm just not sure what the best way to handle this security wise. sorry for bad english.
$$anonymous$$y question is: Why use SQL xamp and php in unity lmao why cant you use c#
Your answer
Follow this Question
Related Questions
Unity PHP login always returning true 3 Answers
Mysql PDO Register user insert not inserting, no error feedback 0 Answers
How Do i check for Duplicate username in database 4 Answers
security with mysql 1 Answer
Unity Null Reference Error 1 Answer