Android アプリケーションにパスワード変更機能を実装しており、php ファイルでパスワードハッシュをコーディングしました。ユーザーはパスワードを変更でき、パスワードはデータベースに保存されます。メールと新しいパスワードでログインしようとすると、間違ったパスワードが表示されます。私のphpファイルのどこが間違っていましたか?
これは私のphpファイルコードです:
<?php
// array for JSON response
$response = array();
function hashSSHA($newpassword) {
$salt = mhash('sha512', rand());
$salt = substr($salt, 0, 15);
$encrypted = hash('sha512', $newpassword . $salt, true) . $salt;
$hash = array("salt" => $salt, "encrypted" => $encrypted);
return $hash;
}
// check for required fields
if (isset($_POST['email']) && isset($_POST['newpassword'])) {
$email = $_POST['email'];
$newpassword = $_POST['newpassword'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// TESTING HERE FOR STORING NEW PASSWORD INTO DATABASE
$hash = hashSSHA($newpassword);
$encrypted_password = $hash["encrypted"]; // encrypted password
$salt = $hash["salt"]; // salt
$result = mysql_query("UPDATE users SET encrypted_password = '$encrypted_password', salt = '$salt' WHERE email = '$email'");
// check if row inserted or not
if ($result) {
// successfully updated
$response["success"] = 1;
$response["message"] = "Password successfully changed";
// echoing JSON response
echo json_encode($response);
} else {
$response["success"] = 0;
$response["message"] = "Password change failed";
echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
// echoing JSON response
echo json_encode($response);
}
?>
編集 これは私の復号化機能です
// DECRYPTING user currentpassword
function checkhashSSHA($salt, $currentpassword) {
$hash = hash('sha512', $currentpassword . $salt, true) . $salt;
return $hash;
}