Reputation: 99
I need to use Joomla crypt password, to be able to register an user. What i'm using right now is:
$query="update table_user set password=md5(password) where id_user='{$form->data['id_user']}'";
$db->setQuery($query);
$db->query();
My question is: how to transform this password into a valid and crypted like joomla passwords?
This question is not duplicated cause old questions is very olds and cant be applicated currently.
Upvotes: 1
Views: 1406
Reputation: 19743
Joomla 3.x uses Bycrypt, not MD5 so your current method is incorrect.
You can use the following to generate the hash:
jimport('joomla.user.helper');
JUserHelper::hashPassword($password);
Where $password
is the password variable.
You may also want to consider using Joomla coding standards for your database query:
https://docs.joomla.org/Inserting,_Updating_and_Removing_data_using_JDatabase
Hope this helps
jimport('joomla.user.helper');
$password = 'however you get the password';
$hash = JUserHelper::hashPassword($password);
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->update($db->quoteName('table_user'))
->set($db->quoteName('password') . ' = ' . $db->quote($hash))
->where($db->quoteName('id_user') . ' = ' . (int)$form->data['id_user']);
$db->setQuery($query);
$result = $db->execute();
You will also need to update $password = 'however you get the password';
as I don't know where you're getting the password from
Upvotes: 2
Reputation: 250
you need to do in following manner.
query= "UPDATE table_user SET password=MD5(‘new password’) WHERE usertype = 'Super Administrator'";
$db->setQuery($query);
$db->query();
Upvotes: 0