Today I am facing a new challenge, implement security password with the PASSWORD HASH encryption method, I am working with postgress and php, but browsing the network I find information from md5, which, to this day , it is not safe anymore, and for password hash I found a very good video , however it is implemented with MySql and the Actually I'm just getting into programming and I do not know how to make it functional for postgres.
If anyone knows how to achieve it or knows another way to implement this method for postgres, I would appreciate it very much.
It is worth mentioning that I am currently working with md5
HTML code
<?php
include_once "includes/valid/validUser.php";
include_once "includes/bdConection.php";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Login</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta charset="UTF-8">
</head>
<body>
<div id="content">
<div class="testbox">
<h1>Inicio de sesión</h1><hr/>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" href="#" >
<label id="icon" for="name"><i class="icon-user"></i></label>
<input type="number" class="inputLogin" name="userNameLogin" placeholder="Código de Usuario" required />
<label id="icon" for="name"><i class="icon-shield"></i></label>
<input type="password" class="inputLogin" name="passwordLogin" value="" placeholder="Contraseña" required/>
<input type="submit" class= "btn btn-info btn-responsive btninter center" id="button" name="submit" value="Ingresar"/>
</form>
</div>
</div>
</body>
</html>
validUser.php code
<?php
include_once "includes/bdConection.php";
if(isset($_POST['submit'])){
$userName=trim($_POST["userNameLogin"]);
$password=trim($_POST["passwordLogin"]);
$password=md5($password);
$query = "SELECT * FROM users WHERE id_user = '$userName' AND pw = '$password';";
$result = pg_query($conn, $query) or die('Query failed: ' . pg_last_error());
if(pg_num_rows($result) != 1) {
//do error stuff
$error = "<b> Usuario o contraseña incorrectos</b>";
}
else
{
session_start();
$_SESSION['varname'] = $userName;
$_SESSION['start'] = time();
$_SESSION['expire'] = $_SESSION['start'] + (60 * 60);
echo "Welcome " . $userName;
header("Location: ../index.php");
exit;
}
}
echo "<p> $error </p>";
?>