Hello I have a small problem with my code. The thing is that in minecraft server the user is asked to register and then his registration details go into mysql database and password is encrypted in SHA256 custom hash. Here is its algorithm:
String salt = randomString(length:16);
String encryptedPassword = "$SHA$" + salt + "$" + sha256(sha256(password) + salt);
The problem is that I need to people to login to my website using that password and their username. But in order to check it I need to encode mine password and check if they are the same. But my code does not seem to work, I've tried everything. please help me. Thank you!!:
<?php
require_once 'config.php';
$mysqli = new mysqli($hostname, $user, $pass, $db4);
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
$name = 'name';
$password = 'password';
$v = $mysqli->query("SELECT password FROM authme WHERE username = '".$name."'");
if ($v->num_rows > 0) {
$row = $v->fetch_assoc();
echo $row['password'];
}
else {
echo 'There is no user with such name';
exit();
}
function checkPassword($password,$row['password']){
$parts = explode('$',$row['password']);
$salt = $parts[2];
$hashed = hash('sha256',hash('sha256', $password).$salt);
$hashed = '$SHA$'.$salt.'$'.$hashed;
if ($hashed == $row['password'])
{
return true;
}
else {
return false;
}
}
if (checkPassword($password, $row['password']) === true) {
echo 'OMGGGGGGGGGGGGGGGGGGGG';
}
else {
echo 'something went wrong';
}
$mysqli->close();
?>