What I want to accomplish is I have two screens. First is member login screen 
(users_controller.php) which takes userid and password. I want the password to 
be hashed. The second screen is change password 
screen(usersinfo_controller.php) . In that screen too the password needs to be 
hashed. In both the classes i defined

var $components = array('Auth'); The function to look for in 
usersinfo_controller.php is changepassword() and in users_controller.php its 
login().

 

Now what happens is: If I comment out the components variable in change 
password screen, then the password is hashed in member login screen otherwise 
the password is not hashed.

 

Hope I have been clear. The code is attached with this email.

 

Thanks,

Bharani
 
> Date: Tue, 24 Feb 2009 01:09:07 -0800
> Subject: Re: AuthComponent problem
> From: lecter...@gmail.com
> To: cake-php@googlegroups.com
> 
> 
> If you're having problem with a piece of your code, use the CakeBin
> (http://bin.cakephp.org/) to show us your code, give us a detailed
> description of your problem, i.e. what do you want to accomplish, what
> is the expected output and what is the output you're getting.
> 
> Then someone might try to answer your question.
> 
> On Feb 24, 8:05 am, lakersfan74 <lakersfa...@msn.com> wrote:
> > Hello,
> >      I have a problem with AutoComponent. I want to use AutoComponent in two
> > different controllers. If I use it in only one controller its fine. If I use
> > it in the second controller, the AutoComponent in the first controller is
> > not valid and password field is not encrypted.
> >
> > Any help will be greatly appreciated.
> >
> > Thanks,
> > Bharani
> > --
> > View this message in 
> > context:http://www.nabble.com/AuthComponent-problem-tp22176142p22176142.html
> > Sent from the CakePHP mailing list archive at Nabble.com.
> > 

_________________________________________________________________
Windows Liveā„¢: Discover 10 secrets about the new Windows Live.  
http://windowslive.com/connect/post/jamiethomson.spaces.live.com-Blog-cns!550F681DAD532637!7540.entry?ocid=TXT_TAGLM_WL_t2_ugc_post_022009
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

<?php
class UsersController extends AppController
{
    var $name = 'tbuser';
    var $components = array('Auth', 'kcaptcha'); 
        var $uses = array('tbuser'); 
        
    
         function beforeFilter() {
        $this->Auth->fields = array('username' => 'username', 'password' => 
'password');
        $this->Auth->allow('register','kcaptcha' );
                // count no of live users 
                $n = $this->tbuser->findAll($conditions = 
"IsUserOnline=1","count(IsUserOnline ) as 'count'");
        $this->set('live_user',$n[0][0]['count']);
    }
        
        function index()
   {
         $this->set('users', $this->User->findAll());
   }
        function liveuser()
        {
                $comments = $this->tbuser->findAll($conditions = 
"IsUserOnline=1","count(IsUserOnline ) as 'count'");
                $this->set('data', $comments); 
                $this->layout = 'ajax';
        }
        
    /**
     * This method handle the user registration process.
     * It will first of all, get the user basic information.
     * After user submit the information, a hash key will be generated and 
     * stored in the database. An email will then send to user and pending
     * for user activation
     */
    function register()
    {
                $this->set('error',$this->Session->read("language"));
                $this->set('u_name',$this->Session->read("username"));
                
       if($_POST)
            if ( !empty( $this->data ) )
                {
                   $this->data['tbuser']=$this->data['User'];
                   
                   if ($this->data['tbuser']['password'] ==  
$this->Auth->password($this->data['tbuser']['password1'])) 
                   {
                  
                                   if ( 
strtolower($this->data['tbuser']['captcha']) == strtolower( 
$this->Session->read('captcha')) ) {
                        $temp = array( 
                                'registerDate'=> date('Y-m-d'), 
                                'activation'=>0, 
                                'IsUserOnline' => 0 );
                        $this->data['tbuser'] = array_merge( 
$this->data['tbuser'], $temp );
                                                
$this->data['tbuser']['password'] = $this->Auth->password( 
$this->data['User']['password1']);
                                                
if($this->data['tbuser']['userphoto']['name']=="")
                                                        
$this->data['tbuser']['userphoto']="no_img.jpg";
                                                else
                                                        $fileOK = 
move_uploaded_file($this->data['tbuser']['userphoto']['tmp_name'],"img/".$this->data['tbuser']['userphoto']['name']);
                                                $val= 
$this->tbuser->save($this->data);
                                                if($val)
                                                        
$this->set('error_msg',__('Your Information is Successfully Inserted..'));

                                                $body = __("To confirm your 
email id for TCR Site please click on this link 
http://www.thecueroom.com/users/".md5($this->data['tbuser']['username']));
                                                $to = 
$this->data['tbuser']['email'];
                                                $sub = __("Activate your 
account");
                                                                                
                
                                                $headers  = "From: TCR Site 
<cont...@pixelfreshgames.com>";
                                                $headers .= 'MIME-Version: 1.0' 
. "\r\n";
                                                $headers .= 'Content-type: 
text/html; charset=iso-8859-1' . "\r\n";
                                                echo "before email";
                                                mail($to,$sub,$body,$headers);

                           } else {
                        //$this->Session->setFlash('captcha verification 
failed');
                                                
$this->set('error_msg',__('captcha verification failed'));
                    }
            } else {
                $this->set('error_msg',__('password mismatch',true));
                                //$this->Session->setFlash(__('password 
mismatch',true));
                                // $this->flash(__('Incorrect session 
data.',true));
            }
        } 
    }
        function user_confirm($id)
        {

                $this->tbuser->id=$id;
                $this->set('userData',$this->tbuser->read());
                $this->data['tbuser']['activation']=1; 
                $this->tbuser->save($this->data['tbuser']) ;
        }

 function login()
    {
                $this->set('error',$this->Session->read("language"));
                $this->set('u_name',$this->Session->read("username"));
                if(!empty($this->data))
                {
//                              echo "Inside Login<br>";
//                              echo pr($this->data['tbuser/password']);
                                echo pr($this->data);
                        if(isset($this->data['tbuser/username']) && 
isset($this->data['tbuser/password']))
                        {
                                $username=$this->data['tbuser/username'];
                                $password=$this->data['tbuser/password'];
                                
$password=$this->Auth->password($this->data['tbuser/password']);        
                                                                
                                $con=$this->tbuser->findAll($condition= 
"tbuser.username='".$username."' and tbuser.password='".$password."'");
                                if(!$con){
                                        $this->Session->delete('username');
                                        $this->Session->setFlash(__('Invalid 
username or password.',true));
                                         //$this->flash(__('Incorrect session 
data.',true));
                                        $this->redirect('/users/login');
                                        exit();
                                }
                                else
                                {
                                        foreach($con as $key)
                                        {
                                                $this -> Session -> 
write("username",$key['tbuser']['username']);
                                                $this -> Session -> 
write("sessionid",session_id());
                                                $this -> Session -> 
write("userID",$key['tbuser']['id']);
                                                
                                        }
                                        $id=$this->Session->read("userID");
                                        $this->tbuser->id=$id;
                                        $this->data= $val=$this->tbuser->read();
                                        $this->data['tbuser']['IsUserOnline']=1;
                                        $this->tbuser->save($this->data);
                                        $this->layout="userlogin";      
                                        $this->redirect('/userinfos/home');
                                }                                               
         
                        }
                        
                }
        }
        function kcaptcha()
        {
                $this->kcaptcha->render(); 
        }     

}
?>
<?php
class userinfosController extends AppController
{
    var $name = 'tbuser';
    var $components = array('Auth'); 
        var $uses = array('tbuser');
        function beforeFilter() 
        {
                $n = $this->tbuser->findAll($conditions = 
"IsUserOnline=1","count(IsUserOnline ) as 'count'");
        $this->set('live_user',$n[0][0]['count']);
                
        }
        function home()
        {
                echo "Inside userinfos home()";
                $this->set('u_name',$this->Session->read("username"));
                $this->set('error',$this->Session->read("language")); 
                
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";

                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect('/users/login');
                }
        }
        function getCountLiveUsers() 
        {
         $n = $this->tbuser->findAll($conditions = 
"IsUserOnline=1","count(IsUserOnline ) as 'count'");
          return $n;
    } 
        function about()
        {
                $this->set('u_name',$this->Session->read("username"));
                $this->set('error',$this->Session->read("language")); 
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";                       
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect('/users/login');
                }
        }
        function play()
        {
                $this->set('u_name',$this->Session->read("username"));
                $this->set('error',$this->Session->read("language"));    
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";                      
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect('/users/login');
                }
        }
        function faq()
        {
                $this->set('u_name',$this->Session->read("username"));
                $this->set('error',$this->Session->read("language"));    
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";              
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect('/users/login');
                }
        }
        function competition()
        {
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";
                        $this->set('u_name',$this->Session->read("username"));
                        $this->set('error',$this->Session->read("language"));   
 
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect('/users/login');
                }
        }
        function setval()
   {
                $this->set('u_name',$this->Session->read("username"));
                $this->set('error',$this->Session->read("language")); 
   }
        function ladder()
        {
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";
                        $this->set('u_name',$this->Session->read("username"));
                        $this->set('error',$this->Session->read("language"));   
 
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect('/users/login');
                }
        }
        function otheruser()
        {
                $this->set('u_name',$this->Session->read("username"));
                        $this->set('error',$this->Session->read("language")); 
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";
                                 
                        
                }
                $this->set('data',$this->tbuser->findAll());
        }
        function userprofile($id)
        {
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";       
                        $this->tbuser->id=$id;
                        $this->set('data',$this->tbuser->read());
                        $this->set('u_name',$this->Session->read("username"));
                        $this->set('error',$this->Session->read("language")); 
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect('/users/login');
                }
        }
        function forgotpassword()
        {
                $this->set('u_name',$this->Session->read("username"));
                $this->set('error',$this->Session->read("language")); 
                if(!empty($this->data))
                {
                        
                        if($this->data['tbuser']['username']!='')
                        {
                                $uname=$this->data['tbuser']['username'];
                                $con=$this->tbuser->findAll($condition=" 
tbuser.username='".$uname."'","tbuser.email,tbuser.password");

                                if(!empty($con))
                                {
                                        
$password=($con[0]['tbuser']['password']);
        
                                        $to=($con[0]['tbuser']['email']);
                                        
                                        $subject="Password form TCR";
                                        
                                        $body=" Password : ".$password;
                                        
                                        $header="From: TCR Site 
<cont...@pixelfreshgames.com>";
                                        $header.='MIME-Version: 1.0' ."\r\n";
                                        $header.='Contaten-Type: text/html; 
charset=iso-8859-1' ."\r\n";
                                        mail($to,$subject,$body,$header);
                                }
                                else
                                {
                                        $this->set('error_msg',__('Your User 
Name is invalid....(Try Again)'));
                                }
                                
                        }       
                        else if($this->data['tbuser']['email']!='')
                        {
                                $email=$this->data['tbuser']['email'];
                                $con=$this->tbuser->findAll($condition=" 
tbuser.email='".$email."'","tbuser.password");
                                if(!empty($con))
                                {
                                        
$password=($con[0]['tbuser']['password']);
        
                                        $to=$email;
                                        
                                        $subject="Password form TCR";
                                        
                                        $body=" Password : ".$password;
                                        
                                        $header="From: TCR Site 
<cont...@pixelfreshgames.com>";
                                        $header.='MIME-Version: 1.0' ."\r\n";
                                        $header.='Contaten-Type: text/html; 
charset=iso-8859-1' ."\r\n";
                                        mail($to,$subject,$body,$header);
                                }
                                else
                                {
                                        //$this->validateErrors($this->tbuser);
                                        //$this->render();
                                        $this->set('error',__('Your Email 
Address is invalid ...(Try Again)'));

                                }
                        }
                        else
                        {
                                $this->set('error',__('Your User name/ Password 
is invalid ....'));

                        }
                }
        }
        function changepassword()
        {
                echo pr($this->data);
                $id=$this->Session->read("userID");
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";      
                        $this->set('u_name',$this->Session->read("username"));
                $this->set('error',$this->Session->read("language"));  
                        if(!empty($this->data))
                        {
                                //$curpass=$this->data['tbuser']['password'];
                                echo pr($this->Auth);
                                $this->data['password'] = 
$this->Auth->password($this->data['password']);
                                
                                $newpass=$this->data['New Password'];
                                $this->tbuser->id=$id;
                                $userinfo=$this->tbuser->read();
                                $userinfo['tbuser']['password']=$newpass;
                                $this->data=$userinfo;
                                $this->tbuser->save($this->data);
                        }
                        
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect("/users/login");
                        
                }
        }
        function myprofile()
        {
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";       
                
                        $id=$this->Session->read("userID");
                        $this->tbuser->id=$id;
                        $this->set('data',$this->tbuser->read());
                        $this->set('u_name',$this->Session->read("username"));
                        $this->set('error',$this->Session->read("language")); 
                }
                else
                {
                        $this->Session->SetFlash('You need to be logged in to 
access this area');
                        $this->redirect("/users/login");
                }               
        }
        function lang_fre()
        {
                /* to get url echo  Router::url('/', true);
                print_r ($this->params['pass']);*/
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";
                }
                $this->Session->Write('language','fre');
                $this->set('error', 'fre');
                $this->Session->read("username");
                $this->set('u_name',$this->Session->read("username"));
                $this->redirect($this->referer()); 
        }
        function lang_eng()
        {
                if($this->Session->check("username"))
                {
                        $this->layout="userlogin";
                        $this->Session->read("username");
                        $this->set('u_name',$this->Session->read("username"));
                }
                $this->Session->Write('language','eng)');
                $this->set('error', 'eng');
                $this->redirect($this->referer()); 
                
        }       
}
?>

Reply via email to