+ 4

trying to update user password columm in my database i need some help sololearners

<?php session_start(); $new_pass=$_POST['new_pass']; $start_session=$_SESSION['u_id']; include_once 'dbh.inc.php'; $sql = "UPDATE users SET user_pwd = $new_pass WHERE user_id= $start_session"; if (mysqli_query($conn, $sql)) { header("Location: ../login.php?password change =succesful"); } else { echo "Error updating record: " . mysqli_error($conn); mysqli_close($conn); } ?> this code updates the password columm of my database but the problem just the plain password not as hased password but when i try to hash the password when updating it gives me an error <?php session_start(); $new_pass=$_POST['new_pass']; $start_session=$_SESSION['u_id']; include_once 'dbh.inc.php'; password_hash($new_pass, PASSWORD_DEFAULT); $sql = "UPDATE users SET user_pwd = $new_pass WHERE user_id= $start_session"; if (mysqli_query($conn, $sql)) { header("Location: ../login.php?password change =succesful"); } else { echo "Error updating record: " . mysqli_error($conn); mysqli_close($conn); } ?>

11th Mar 2018, 7:28 PM
Franklyn Omeben
Franklyn Omeben - avatar
1 Resposta
0
i think your method password_hash should be return the password in a new variable like this $hash_pass = password_hash($new_pass, PASSWORD_DEFAULT); than don't forget to use $hash_pass instead of $new_pass or it could be a problem in your database that the password field don't accept the hash (maybe to long?)
12th Mar 2018, 8:44 AM
Stefanoo
Stefanoo - avatar