I'm trying to hash my inserted passwords in PHP but whatever password I insert, the SHA output is always the same. Here are my files, create-user.php:
<?php include 'header.php' ?>
<body>
<form action="insert-user.php" method="post" role="form">
<div class="form-group">
<label for="username">Enter Username:</label>
<input type="text" class="form-control" name="username" placeholder="e.g. username12" required>
</div>
<div class="form-group">
<label for="password">Enter Password:</label>
<input type="password" class="form-control" name="password" placeholder="e.g. mypass912" required>
</div>
<div class="form-group">
<label for="email">Enter Email Address:</label>
<input type="email" class="form-control" name="email" placeholder="e.g. myemail56@hotmail.com" required>
</div>
<div class="form-group">
<label for="bdate">Your Birthdate:</label>
<input type="date" class="form-control" name="bdate" required>
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</body>
</html>
Here the insert-user.php:
<?php
include 'header.php';
$username=mysqli_real_escape_string($con,$_POST['username']);
$password=mysqli_real_escape_string($con,hash('sha256','$_POST[password]'));
$email=mysqli_real_escape_string($con,$_POST['email']);
$bdate=mysqli_real_escape_string($con,$_POST['bdate']);
$sql="INSERT INTO users (username,password,email,bdate)
VALUES('$username','$password','$email','$bdate')";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
echo "User added!";
mysqli_close($con);
?>
Could someone explain how I can get the SHA2 function working correctly?