decrypt a previously encrypted database element with mySQL

0

When I save a password element in my database, I save it with

sha1 (...) and this is saved, for example, if I put hello , in the following way: fc1815288c56c87a05ef3cfd10738015bc5c1129

<?php 
$conexion=mysqli_connect('localhost','root','','pruebas');

$nombre=$_POST['nombre'];
$apellido=$_POST['apellido'];
$usuario=$_POST['usuario'];
$password=sha1($_POST['password']);

$sql="INSERT into usuarios (nombre,apellido,usuario,password)
        values ('$nombre','$apellido','$usuario','$password')";
echo mysqli_query($conexion,$sql);
?>

My question is, how can I from a web page, recover this deciphered value, that is, hello ?

Thanks

    
asked by Vidal 17.03.2018 в 19:30
source

1 answer

1

Greetings the SHA1 method like others helps me create an output with an alphanumeric or hashed combination.

Among the most common we have MD5 (), SHA1, SALT (); however, the most advisable is to use password_hash () ; the results of data that are hashed are not recovered to their original form, what they do internally, for example, PHP is to compare the internal hash with the one entered by the user.

How to use:

$contrasenia = password_hash("alfredo", PASSWORD_DEFAULT);

Now, through the verify () method, I will check that the hash entered corresponds to the one stored in the DB

$password_usuario_ingresa = $_POST['password'];
$coincidencia = password_verify($password_usuario_ingresa, $contrasenia);

I'll just save with an if I check if both values match

if($coincidencia) {
 echo "Los valores coinciden";
} else {
 echo "Los valores no coinciden";
}

Greetings I hope to have explained.

    
answered by 17.03.2018 / 19:40
source