Joomla.it Forum
Non solo Joomla... => Database => : pippo30 19 Apr 2013, 17:09:12
-
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword($pwd, $salt) . ':' . $salt;
$newpassword= $crypted . ':' . $salt;
66ef5564d2b51e90e8eb3001a275c304:yBHNNgTiBQYTzo1X4..password csv
fd8c5fc32d89843ffe861c5727058eab:eEORBOeZ3erYenV1r... password cambiata a mano
come mai???
-
Il salt è diverso se lo fa joomla rispetto a come lo fai tu a mano?
-
io ho fatto un componente che imprta il csv utenti
sono riuscito a fare in modo che gli utenti si importino da csv le passord sono criptate male
se io le importo da csv sono diversere rispetto a quando vado a inserile nella gestione utenti e la modifico a mano.
se la stessa password la metto a mano funziona se la importo da csv ne cripta un'altra
se mi dai una mano ti rigrazio
-
Come le modifichi a mano?
-
le modifico d'amministrazione utenti di joomla ti posto il mio controller.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of JUserImporter component
*/
class JUserImporterController extends JControllerLegacy
{
/**
* display task
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'JUserImporter'));
// call parent behavior
parent::display($cachable, $urlparams);
}
/**
* Import task
*/
function importUsers($source = "D:/xampp/htdocs/users2import.csv")
{
/* Check the user file exists */
/* Open the file */
if(!file_exists($source)) $source = $_REQUEST['srcfile'];
$handle = fopen($source,"r");
$content = fread ($handle,filesize ( $source ));
/* Get the file, line by line */
$lines = explode("\n", $content);
fclose($handle);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
foreach ($lines as $line){
/* Split the line by comma */
$properties = explode(",",$line);
/* Build a new user object */
$user = new JUser();
$user->name = $properties[0];
$user->username = $properties[1];
$user->email = $properties[2];
$user->password = $properties[3];
$user->id = null;
/* Set the values */
$user->groups = array(2);
require_once( JPATH_ROOT . "/libraries/joomla/user/helper.php" ); // Needed to create password
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword($pwd, $salt) . ':' . $salt;
$newpassword= $crypted . ':' . $salt;
$user->password = $newpassword;
$user->registerDate = date('Y-m-d H:i:s');
if(!$user->save()) JError::raiseError(500,$user->getError() );
else $added++;
}
if($added) return $added;
JError::raiseError(403, JText::_('Ci sono stati degli errori.'));
return false;
}
}
pensavo fosse la mancanza di questa riga:
require_once( JPATH_ROOT . "/libraries/joomla/user/helper.php" ); // Needed to create password che richiama helper.php
praticamente ho richiamato questo file che è il che genera l'hd5??? giusto??
-
ciao ho provato a mettere in due array sia $salt che $crypt nn cambia nulla
$salt = JUserHelper::genRandomPassword(32);
$crypt = JUserHelper::getCryptedPassword($array['password'], $salt);
$array['password'] = $crypt . ':' . $salt;
-
Vedi se questa discussione ti può essere utile.
http://forum.joomla.it/index.php/topic,172915.msg780484.html#msg780484 (http://forum.joomla.it/index.php/topic,172915.msg780484.html#msg780484)
-
nn capidco come lo spiegano
-
In quella discussione l'utente ha utilizzato questo codice:
function password__serialize($username, $password){
$query = "SELECT id, gid, block, password, usertype FROM jos_users where username='".$username."'";
$risultato = mysql_query($query) or die("Query fallita: " . mysql_error() );
$linea = mysql_fetch_array($risultato, MYSQL_ASSOC);
/* Liberazione delle risorse del risultato */
mysql_free_result($risultato);
$arraypass=explode(":", $linea['password']);
$salt=$arraypass[1];
$ret = md5(trim($password).$salt).":".$salt;
return $ret;
}
$username = "pippo";
$password = "pippo";
echo password__serialize($username, $password);
-
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of JUserImporter component
*/
class JUserImporterController extends JControllerLegacy
{
/**
* display task
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'JUserImporter'));
// call parent behavior
parent::display($cachable, $urlparams);
}
/**
* Import task
*/
function importUsers($source = "e:/xampp/htdocs/users2import.csv")
{
/* Check the user file exists */
/* Open the file */
if(!file_exists($source)) $source = $_REQUEST['srcfile'];
$handle = fopen($source,"r");
$content = fread ($handle,filesize ( $source ));
/* Get the file, line by line */
$lines = explode("\n", $content);
fclose($handle);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
foreach ($lines as $line){
/* Split the line by comma */
$properties = explode(",",$line);
/* Build a new user object */
$user = new JUser();
$data = array();
$data['name'] = $properties[0];
$data['username'] = $properties[1];
$data['email'] = $properties[2];
$data['password'] = $properties[3];
// Load the users plugin group.
JPluginHelper::importPlugin('user');
/* Set the values */
$user->groups = array(2);
if (!$user->bind($data))
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
return false;
}
/* Build the password */
$salt = JUserHelper::genRandomPassword(32);
$crypted = JUserHelper::getCryptedPassword( preg_replace("/\s/", "", strtolower($line[3])) , $salt);
$newpassword= $crypted . ':' . $salt;
$user->registerDate = date('Y-m-d H:i:s');
if (!$user->save())
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}
else $added++;
}
if($added) return $added;
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', "Ci sono stati degli errori nella importazione"));
return false;
}
}
non so perché funzioni solo con l’ultimo utente del csv
se ho questi 3 utenti
luca,luca,luca@alice.it,luca-->no
pippo,pippo@libero.com,pippo@outlook.com,ciao---->no
paolo,paolo@libero,paolo@libero.com,paolo2--> con questo utente fa il login corettamente
come mai???
-
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla controller library
jimport('joomla.application.component.controller');
/**
* General Controller of JUserImporter component
*/
class JUserImporterController extends JControllerLegacy
{
/**
* display task
*
* @return void
*/
function display($cachable = false, $urlparams = array())
{
// set default view if not set
$input = JFactory::getApplication()->input;
$input->set('view', $input->getCmd('view', 'JUserImporter'));
// call parent behavior
parent::display($cachable, $urlparams);
}
/**
* Import task
*/
function importUsers($source = "e:/xampp/htdocs/users2import.csv")
{
/* Check the user file exists */
/* Open the file */
if(!file_exists($source)) $source = $_REQUEST['srcfile'];
$handle = fopen($source,"r");
$content = fread ($handle,filesize ( $source ));
/* Get the file, line by line */
$lines = explode("\n", $content);
fclose($handle);
/* Counter of users added */
$added = 0;
/* Iterate through each line of the data file */
for ($i = 0; $i < count($lines); $i++){// as $key => $line){
/* Split the line by comma */
$properties = explode(",",$lines[$i]);
/* Build a new user object */
$user = new JUser();
$data = array();
$data['name'] = $properties[0];
$data['username'] = $properties[1];
$data['email'] = $properties[2];
$data['password'] = $properties[3];
// Load the users plugin group.
JPluginHelper::importPlugin('user');
/* Set the values */
$user->groups = array(2);
if (!$user->bind($data))
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_BIND_FAILED', $user->getError()));
return false;
}
$user->registerDate = date('Y-m-d H:i:s');
if (!$user->save())
{
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', $user->getError()));
return false;
}
else $added++;
$user = null;
}
if($added) return $added;
$this->setError(JText::sprintf('COM_USERS_REGISTRATION_SAVE_FAILED', "Ci sono stati degli errori nella importazione"));
return false;
}
}
ho usato lo stesso metodo di joomla
/* Iterate through each line of the data file */
for ($i = 0; $i < count($lines); $i++){// as $key => $line){
/* Split the line by comma */
$properties = explode(",",$lines[$i]
alla fine riga del csv una , e un carattere e funziona