Reputation: 191
I successfully hashed my passwords for the new accounts i created, however, when i log in using the previous non-hashed passwords, i can't log in. but i can log in when i use the hashed passwords. so how do i update the previous passwords to be hashed?
Here is the update php file.
<?php
session_start();
$con=@mysql_connect("localhost","root","");
$dbcheck = mysql_select_db("buybranded");
if (!$dbcheck) {
echo mysql_error();
}
$userid = $_GET['user_id'];
$hashed = hash('sha512', $password); // where should i use this? or what should i do with it?
$sql = "UPDATE `users` SET
first_name = '$_POST[first_name]',
middle_name = '$_POST[middle_name]',
last_name = '$_POST[last_name]',
gender = '$_POST[gender]',
email = '$_POST[email]',
password = '$_POST[password]',
birth_date = '$_POST[birth_date]',
company = '$_POST[company]',
company_address = '$_POST[company_address]',
home_address = '$_POST[home_address]',
postal_code = '$_POST[postal_code]',
city = '$_POST[city]',
province = '$_POST[province]',
home_phone = '$_POST[home_phone]',
mobile_phone = '$_POST[mobile_phone]' WHERE id=$userid";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error($con));
}
header('refresh: 0;url=userdb.php');
$message = "User Successfully Updated";
echo("<script type='text/javascript'>alert('$message');</script>");
?>
Upvotes: 0
Views: 187
Reputation: 5090
$hashed = hash('sha512', $_POST['password']);
then in your query use $hashed :
$sql = "...
password = '$hashed',
...";
Upvotes: 1