Can't find: BlowfishPasswordHasher Cakephp - php

I just downloaded CakePHP and was following the tutorials to get the basics. Everything was going ok, until I started with this Authentication system.
If you go to the following url, and to the password hashing block ( of code ).
http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html#authentication-login-and-logout
you will see:
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['password'])) {
$passwordHasher = new BlowfishPasswordHasher();
$this->data[$this->alias]['password'] = $passwordHasher->hash(
$this->data[$this->alias]['password']
);
}
return true;
}
The issue is when I run this, is that I get a Fatal Error on that Line:
Fatal error: Class 'BlowfishPasswordHasher' not found in /Users/myUser/Sites/cake/app/Model/User.php on line 29
This is the line (to be precise):
$passwordHasher = new BlowfishPasswordHasher();
Why isn't it seeing that file ?
In my PHPStorm IDE, when I alt+click on it, it goes to the correct file located in:
/Users/myUser/Sites/cake/lib/Cake/Controller/Component/Auth/BlowfishPasswordHasher.php
Anyone else having issues with this ?
Thanks in advance

Put following line in your User Model
App::uses('BlowfishPasswordHasher', 'Controller/Component/Auth');
class User extends AppModel {
....
}
Note : The BlowfishPasswordHasher uses a stronger hashing algorithm (bcrypt) than SimplePasswordHasher (sha1) and provides per user salts. The SimplePasswordHasher will be removed as of CakePHP version 3.0

Related

Why can I not ClassRegistry::init() my CakePHP model?

I'm not new to frameworks and work with Symfony quite often but I have a legacy version of CakePHP 2.4 that I must maintain for now and am having an issue. My code is this:
function aff($user=null,$pid=null) {
if (empty($user) || empty($pid)) $this->redirect('/');
$userModel =& ClassRegistry::init('User');
$productModel =& ClassRegistry::init('Product');
$granularModel =& ClassRegistry::init('Granular');
$this->autoRender = false;
$temp = array(
'user' => $user,
'pid' => $pid
);
$granularModel->save($temp);
}
This is a function inside my controller. The User and Product models are being ClassRegistry::init just fine and work correctly BUT my Granular model causes the page to load with a message of "The requested address XXXX was not found on this server." Here is my model:
<?php
class Granular extends AppModel {
var $name = 'Granular';
}
?>
Why is it causing the route not to be found? If I put an "echo 'Hello'; exit();" right after the line $productModel =& ClassRegistry::init('Product'); it loads the route just fine. I feel lost. Please help. TIA
For some reason today after turning on Configure::write('debug', 1); in app/config/core.php, it suddenly started working. I am guessing at this point that it must have been a caching issue of some sort.

Fatal error: Class 'Zend_Log' not found

I'm getting the following error in magento administration
Fatal error: Class 'Zend_Log' not found in /home/website/public_html/app/code/community/Uni/Fileuploader/Block/Adminhtml/Fileuploader/Edit/Tab/Products.php on line 241
This is a community extension, which has been working fine on my website. The error makes no sense to me, because the line 241 contains just a closing "}" character.
class Uni_Fileuploader_Block_Adminhtml_Fileuploader_Edit_Tab_Products extends Mage_Adminhtml_Block_Widget_Grid {
...
...
...
public function getRowUrl() {
return '#';
}
public function getGridUrl() {
return $this->getUrl('*/*/productgrid', array('_current' => true));
}
protected function getFileuploaderData() {
return Mage::registry('fileuploader_data');
}
protected function _getSelectedProducts() {
$products = $this->getRequest()->getPost('selected_products');
if (is_null($products)) {
$products = explode(',', $this->getFileuploaderData()->getProductIds());
return (sizeof($products) > 0 ? $products : 0);
}
return $products;
}
} // line 241, where error occurs
I can post the rest of the code, if you need it.
I noticed that if I upgrade to PHP 5.4 version the error disappears, but since 5.4 version causes other errors on my website, I have to continue using 5.3.
Any ideas on how to solve this?
The problem could be the name of one of the methods in your custom class.
Take for example the method name is getData() ,
Try searching for generic method names in your script, such as getData, which might be reserved by some of Magento’s core classes. I figure that these methods have predefined functionality, which your module is missing support for, and Zend then tries to write an exception to Zend log.
Reference link: netismine
I got the same error when rewriting a payment method.
public function authorize($payment, $amount)
Solved rewriting exactly the same main method:
public function authorize(Varien_Object $payment, $amount)
Magento 1.9.1.0/PHP 5.5

Fatal error in joomla component

i just installed a new component in my site but when i click on component settings button in the backend i am getting this message:
Fatal error: Call to a member function loadByOption() on a non-object in /mysite.com/administrator/components/com_sigpro/models/settings.php on line 32
the file contains this code:
defined('_JEXEC') or die ;
class SigProModelSettings extends SigProModel
{
protected $extensionID = null;
public function getForm()
{
$option = $this->getState('option');
if (version_compare(JVERSION, '2.5.0', 'ge'))
{
$component = JComponentHelper::getComponent($option);
$this->extensionID = $component->id;
JForm::addFormPath(JPATH_ADMINISTRATOR.'/components/'.$option);
$form = JForm::getInstance($option.'.settings', 'config', array('control' => 'jform'), false, '/config');
$form->bind($component->params);
}
else
{
$component = JTable::getInstance('component');
$component->loadByOption($option);
$this->extensionID = $component->id;
$form = new JParameter($component->params, JPATH_ADMINISTRATOR.DS.'components'.DS.$option.DS.'config.xml');
}
return $form;
}
PS my site is running Joomla 1.7.5 stable version and i cant upgrade it to 2.5 because the site is online and productive some components dont works on version 2.5 .
So i will appreciate it if someone can help me fix this error.
Thanks in advance
you 1.6 needs 1.6 specific modules, components & plugins. You'll need to find a 1.6 compatible version or alternative or check the permissions on /configuration.php
Looks like the table class is not present in your file system. It should have been there in the /mysite.com/administrator/components/com_sigpro/tables folder , somewhere ( may vary depending on the code, but looks like they have not included a custom path ). The class should extends JTable class.

Why I can't load models in modules?! [Using HMVC in codeigniter 2.1.2]

I hope someone can help me with this one before I jump off the window. I spent few hours on this one and don't know what am I doing wrong.
Basically, I've installed HMVC in CodeIgniter 2.1.2 and everything works fine, BUT for some reason I can't load models the same way I'm doing it in standard controllers. In the old codeigniter 1.7.1 I could use it simply by invoking $this->load->model('my_model') but now I can't?!
Every single time I'm trying to load model I get this error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Special_cart::$db
Filename: core/Model.php
Line Number: 51
I have had installed it step-by-step according to the instructions. I got third_party next to modules folder. In modules I have few modules stored like this:
modules
--boxes
----controller
----models
----views
I invoke module in my code like this:
<?=modules::run('boxes/special_cart/index');?>
My module controller code looks like this:
class Special_cart extends CI_Controller
{
public function __construct()
{
parent::__construct();
}
public function index()
{
if ($this->session->userdata('cart'))
{
# get product id's and each quantity
$cart_product_list = array_count_values($this->session->userdata('cart'));
# get list of product_id
$product_list = array_keys($cart_product_list);
# get product details
$this->load->model('productmodel');
$this->load->model('stockmodel');
$cart_products = $this->productmodel->cart_get_products_details($product_list);
$final_cart_array = array();
foreach($cart_products as $cart_product){
$product_stock = $this->stockmodel->view_product_stock($cart_product["id"]);
if(empty($product_stock) || $product_stock["UNITS"]<=0)
$cart_product["UNITS"] = 0;
else{
if($cart_product_list[$cart_product["id_web"]]>$product_stock["UNITS"])
$cart_product["UNITS"] = $product_stock["UNITS"];
else{
$cart_product["UNITS"] = $cart_product_list[$cart_product["id_web"]];
}
}
$final_cart_array[] = $cart_product;
}
$refresh_cart_array = array();
foreach($final_cart_array as $cart_product){
for($i=1;$i<=$cart_product["UNITS"];$i++){
$refresh_cart_array[] = $cart_product["id_web"];
}
}
$this->load->view("special_cart",array(
'refresh_cart_array' => $refresh_cart_array,
'final_cart_array' => $final_cart_array
));
} else {
$this->load->view("special_cart",array(
'refresh_cart_array' => NULL,
'final_cart_array' => NULL
));
}
}
}
I've tried every possible solution found on internet - none of them work....
I hope you understand my problem but in case you need some further explanation please ask me. Can anyone help?
Looks like the model you're trying to load wants to connect to the db, but the database driver is not available. If you use database queries in your application, why don't you load the database driver automatically?
Just insert "database" in the "libraries" array in application/config/autoload.php file. Don't forget to insert your database credentials into application/config/database.php.
$autoload['libraries'] = array('database');
If you need database connection just in one single model, load it before trying to access database library.
$this->load->database();
Try loading the model stating the module name as follows
$this->load->model('module_name/productmodel');
Class Models extends MX_Loader{
function getUser($username){
$sql="SELECT * FROM user WHERE username = ? ";
return $this->db->query($sql,array($username))->row();
}
}
you must using extends MX_Loader because i don't know if using CI_Model the database core cant be load in Codeigniter,,,
Try to use extend MX_Controller class (not CI_Contoller like you are doing atm)
Based on what you have wrote in comment above, I figured that you tried to create new instance of DB in module (based on chrises comment).
Do it on constuctor of Special_cart
So update current construct to be like
public function __construct()
{
parent::__construct();
$this->load->database('default');
}
(I'm writing this from top of my head, so check the methods)
Now for sure db driver should be available in your models.
Regarding issue with HMVC I dont think there are any. I'm using HMVC for a while now, and I found no problems in it (working with databases)
I had the same problem and mistake. I missed to extend controllers to MX_Controller. So the solution would be to change CI_Controller to MX_Controller like this:
class Special_cart extends MX_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('productmodel');
$this->load->model('stockmodel');
}
public function index()
{
if ($this->session->userdata('cart'))
{
# get product id's and each quantity
$cart_product_list = array_count_values($this->session->userdata('cart'));
# get list of product_id
$product_list = array_keys($cart_product_list);
# get product details
$cart_products = $this->productmodel->cart_get_products_details($product_list);
$final_cart_array = array();
foreach($cart_products as $cart_product){
$product_stock = $this->stockmodel->view_product_stock($cart_product["id"]);
if(empty($product_stock) || $product_stock["UNITS"]<=0)
$cart_product["UNITS"] = 0;
else{
if($cart_product_list[$cart_product["id_web"]]>$product_stock["UNITS"])
$cart_product["UNITS"] = $product_stock["UNITS"];
else{
$cart_product["UNITS"] = $cart_product_list[$cart_product["id_web"]];
}
}
$final_cart_array[] = $cart_product;
}
$refresh_cart_array = array();
foreach($final_cart_array as $cart_product){
for($i=1;$i<=$cart_product["UNITS"];$i++){
$refresh_cart_array[] = $cart_product["id_web"];
}
}
$this->load->view("special_cart",array(
'refresh_cart_array' => $refresh_cart_array,
'final_cart_array' => $final_cart_array
));
} else {
$this->load->view("special_cart",array(
'refresh_cart_array' => NULL,
'final_cart_array' => NULL
));
}
}
}
this is also explained in the documentation
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/
, here the quote:
Notes:
To use HMVC functionality, such as Modules::run(), controllers must
extend the MX_Controller class. To use Modular Separation only,
without HMVC, controllers will extend the CodeIgniter Controller
class. You must use PHP5 style constructors in your controllers. ie:
<?php
class Xyz extends MX_Controller
{
function __construct()
{
parent::__construct();
}
}

access to extended class in symfony 1.4

so... I basically follow the practical symfony book, and encountered following problem.
I have properly (i guess) installed sfGuardPlugin, built the models, sqls etc, created user and tried to log in with the username and password entered.
i got the following error message:
Fatal error: Call to undefined method sfGuardUserPeer::retrieveByUsername() in /***/plugins/sfGuardPlugin/lib/validator/sfGuardValidatorUser.class.php on line 53
it looks quite weird to me, because the problematic part of sfGuardValidatorUser class looks like this:
// user exists?
if ($user = sfGuardUserPeer::retrieveByUsername($username))
{
// password is ok?
if ($user->getIsActive() && $user->checkPassword($password))
{
return array_merge($values, array('user' => $user));
}
}
while sfGuardUserPeer has just the empty class:
class sfGuardUserPeer extends PluginsfGuardUserPeer
{
}
that extends PluginsfGuardUserPeer, so i checked it out too:
class PluginsfGuardUserPeer extends BasesfGuardUserPeer
{
public static function retrieveByUsername($username, $isActive = true)
{
$c = new Criteria();
$c->add(self::USERNAME, $username);
$c->add(self::IS_ACTIVE, $isActive);
return self::doSelectOne($c);
}
}
that's the missing function!
so - what is wrong? why doesn't it work?
i have already tried all the solutions found with google, but none of them work :/
finally found it!
the
symfony propel:build-model
task unnecessarily generated the sfGuard classes in the model directory from the schema file located in the plugin directory, while all the classes were already present in the sfGuard folder.
geez, that shouldn't happen in such a well-developed framework and plugin...
Simply put that
public static function retrieveByUsername($username, $isActive = true)
{
$c = new Criteria();
$c->add(self::USERNAME, $username);
$c->add(self::IS_ACTIVE, $isActive);
return self::doSelectOne($c);
}
Code into your sfGuardUserPeer class, this will sort out the issue, I did the same when I got this error, it worked for me..

Categories