0
How do I select the code for HASH in Nodejs?
I have a system made in another language with passwords encrypted with SHA256
The encryption function there is so:
#define HASH_CODE = 'WEASDSAEWEWAEAWEAWEWA';
SHA256_PassHash(HASH_CODE, password, 64);
The hash was here (for password 123): 8A8E0E514F3A1F3D160C58C99BC66C81A10256E6A3462002A53ADACAD6C43EAB
First parameter is the HASH code, the second is the value to be encrypted and the third is Base64
I was able to encrypt in Nodejs, but I don’t have control of the HASH code, so the systems don’t create the same HASH, as I do to select the HASH code when registering in Nodejs so that it can communicate with this other system?
const code = 'WEASDSAEWEWAEAWEAWEWA';
const normal = 'anne';
const crypto = require('crypto');
const encryptado = crypto
.createHash('sha256')
.update(normal)
.digest('base64');
console.log(encryptado);
The hash was here (for password 123): 8A8E0E514F3A1F3D160C58C99BC66C81A10256E6A3462002A53ADACAD6C43EAB
An example of compatible code: login.php
<?php require_once('../mysql_conn.php'); ?>
<?php
session_start();
$HASH_SENHA = 'WEASDSAEWEWAEAWEAWEWA';
if(isset($_SESSION['Username']))
{
header("location: ../myaccount.php");
exit();
}
if(isset($_POST['usr']) && isset($_POST['psw']) && isset($_POST['botao']))
{
$usuario = mysqli_real_escape_string($MYSQL_CONNECT, $_POST['usr']);
$senha = strtoupper(hash("sha256", $_POST['psw'] . $HASH_SENHA));
$query = mysqli_query($MYSQL_CONNECT, "SELECT * FROM accounts WHERE Username='$usuario' AND Senha='$senha' LIMIT 1");
if(mysqli_num_rows($query) < 1)
{
echo "<script type=\"text/javascript\">
alert('Incorrect Username or Password.');
window.location = '../login.php';
</script>";
exit();
}
else
{
//login efetuado
$dados = mysqli_fetch_assoc($query);
if (isset($_SESSION['loc'])) {
header("location:".$_SESSION['loc']);
}
else header("location:../index.php");
}
}
?>
According to your question there is no problem (ignoring the obvious security problems), but in both the result of the hash is equal, according to you. The two cases generate
8A8E0E514F3A1F3D160C58C99BC66C81A10256E6A3462002A53ADACAD6C43EAB
.– Inkeliz
If your question is wrong, and Nodejs generates a different code, you have to concanete the
code
, as.update(normal + code)
.– Inkeliz