Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Hashing Password in CakePHP 2.1
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Charles Blackwell  
View profile  
 More options Apr 29 2012, 3:22 pm
From: Charles Blackwell <charlesblackwell...@gmail.com>
Date: Sun, 29 Apr 2012 12:22:54 -0700 (PDT)
Local: Sun, Apr 29 2012 3:22 pm
Subject: Hashing Password in CakePHP 2.1

This works but, is there a way to NOT has the password when the confirm
method is called? Also, in your opinion is beforeSave a good way to hash
the password?

Thanks!

   1. <?php
   2.     class User extends AppModel {
   3.         public $name = 'User';
   4.        
   5.         public function beforeSave() {
   6.         $this->data['User']['password'] = AuthComponent::password(
   $this->data['User']['password']);
   7.         return true;
   8.     }
   9.  
   10. <?php
   11.     App::uses('CakeEmail', 'Network/Email');
   12.     class UsersController extends AppController {        
   13.         public $name = 'Users';
   14.         public $components = array <http://www.php.net/array>('Auth',
   'Email');
   15.        
   16.         function beforeFilter(){
   17.             $this->Auth->allow('signup', 'confirm');
   18.         }
   19.  
   20.     function signup(){
   21.     if(!empty <http://www.php.net/empty>($this->request->data)){
   22.             $this->request->data['User']['confirm_code'] = String::
   uuid();
   23.                 $this->User->create();
   24.                 if($this->User->save($this->request->data)){
   25.                     $email = new CakeEmail();
   26.                     $email->template('welcome', 'default')
   27.                                 ->emailFormat('html')
   28.                                 ->viewVars(array<http://www.php.net/array>
   (
   29.                                         'id' => $this->User->
   getLastInsertID(),
   30.                                         'username' => $this->request
   ->data['User']['username'],
   31.                                         'email' => $this->request->
   data['User']['email'],
   32.                                         'server' => $_SERVER[
   'SERVER_NAME'],
   33.                                         'code' => $this->request->
   data['User']['confirm_code']
   34.                                         ))
   35.                                 ->from(array<http://www.php.net/array>
   ('quickw...@localhost.com' => 'QuickWall.com Administrator'))
   36.                             ->to($this->request->data['User']['email'
   ])
   37.                             ->subject('Welcome!');
   38.        if($email->send()){
   39.                         $this->Session->setFlash('Congratulations!
   You have signed up!');
   40.                         $this->redirect(array<http://www.php.net/array>
   ('controller' => 'questions', 'action' => 'home'));
   41.                     }
   42.                 } else {
   43.                     $this->Session->setFlash('There was an error
   signing up. Please, try again.');
   44.                     $this->request->data = null;
   45.                 }            
   46.             }
   47.         }
   48.        
   49.         function confirm($user_id=null, $code=null){
   50.             if(empty <http://www.php.net/empty>($user_id) || empty<http://www.php.net/empty>
   ($code)){
   51.                 $this->set('confirmed', 0);
   52.                 $this-render();
   53.                 }
   54.            
   55.             $user = $this->User->read(null, $user_id);
   56.            
   57.             if(empty <http://www.php.net/empty>($user)){
   58.                 $this->set('confirmed', 0);
   59.                 $this->render();
   60.                 }
   61.            
   62.             if($user['User']['confirm_code'] == $code){
   63.                 $this->User->id = $user_id;
   64.                 $this->User->saveField('confirmed', '1');
   65.                 $this->set('confirmed', 1);
   66.                 } else {
   67.                     $this->set('confirmed', 0);
   68.                 }
   69.             }


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tilen Majerle  
View profile  
 More options Apr 29 2012, 3:30 pm
From: Tilen Majerle <tilen.maje...@gmail.com>
Date: Sun, 29 Apr 2012 21:30:30 +0200
Local: Sun, Apr 29 2012 3:30 pm
Subject: Re: Hashing Password in CakePHP 2.1

only PHP basics :)

public function beforeSave()
{
    if (isset($this->data['User']['password'])) {
    $this->data['User']['password'] =
AuthComponent::password($this->data['User']['password']);
    }
    return true;

}

--
Lep pozdrav, Tilen Majerle
http://majerle.eu

2012/4/29 Charles Blackwell <charlesblackwell...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tilen Majerle  
View profile  
 More options Apr 29 2012, 3:32 pm
From: Tilen Majerle <tilen.maje...@gmail.com>
Date: Sun, 29 Apr 2012 21:32:21 +0200
Local: Sun, Apr 29 2012 3:32 pm
Subject: Re: Hashing Password in CakePHP 2.1

Yep...cake's book says that you should there hash password :)
--
Lep pozdrav, Tilen Majerle
http://majerle.eu

2012/4/29 Tilen Majerle <tilen.maje...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Blackwell  
View profile  
 More options Apr 29 2012, 3:37 pm
From: Charles Blackwell <charlesblackwell...@gmail.com>
Date: Sun, 29 Apr 2012 12:37:42 -0700 (PDT)
Local: Sun, Apr 29 2012 3:37 pm
Subject: Re: Hashing Password in CakePHP 2.1

Thanks :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Blackwell  
View profile  
 More options Apr 29 2012, 3:38 pm
From: Charles Blackwell <charlesblackwell...@gmail.com>
Date: Sun, 29 Apr 2012 12:38:29 -0700 (PDT)
Local: Sun, Apr 29 2012 3:38 pm
Subject: Re: Hashing Password in CakePHP 2.1

I am still very new to PHP and Cake.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Blackwell  
View profile  
 More options Apr 29 2012, 3:39 pm
From: Charles Blackwell <charlesblackwell...@gmail.com>
Date: Sun, 29 Apr 2012 12:39:52 -0700 (PDT)
Local: Sun, Apr 29 2012 3:39 pm
Subject: Re: Hashing Password in CakePHP 2.1

I was trying to use $created because I saw it in book. I didn't know if it
was a model property or not. That didn't work and I had a brain freeze, lol.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thiago Belem  
View profile  
 More options Apr 29 2012, 3:40 pm
From: Thiago Belem <cont...@thiagobelem.net>
Date: Sun, 29 Apr 2012 16:40:16 -0300
Local: Sun, Apr 29 2012 3:40 pm
Subject: Re: Hashing Password in CakePHP 2.1

I always recommend a moderate knowlegdge about PHP before adventuring with
frameworks.

There's a lot of things inside the frameworks that require language skills.

Good luck,
--
***Thiago Belem*
Desenvolvedor
Rio de Janeiro - RJ - Brasil

*Assando Sites* - Curso online de *CakePHP*
assando-sites.com.br <http://goo.gl/b1EEd>

thiagobelem.net
cont...@thiagobelem.net

*Skype / gTalk **»* thiago.belem.web
*LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt

On Sun, Apr 29, 2012 at 16:38, Charles Blackwell <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Thiago Belem  
View profile  
 More options Apr 29 2012, 3:41 pm
From: Thiago Belem <cont...@thiagobelem.net>
Date: Sun, 29 Apr 2012 16:41:31 -0300
Local: Sun, Apr 29 2012 3:41 pm
Subject: Re: Hashing Password in CakePHP 2.1

$created is a beforeSave parameter:

public function beforeSave($created = false) {

}

Inside the method, $created will be true if the record was created and
false if it's being updated... but this wouldn't work if you want to change
the user password (since it's an update).

Regards,
--
***Thiago Belem*
Desenvolvedor
Rio de Janeiro - RJ - Brasil

*Assando Sites* - Curso online de *CakePHP*
assando-sites.com.br <http://goo.gl/b1EEd>

thiagobelem.net
cont...@thiagobelem.net

*Skype / gTalk **»* thiago.belem.web
*LinkedIn* *»* br.linkedin.com/in/thiagobelem/pt

On Sun, Apr 29, 2012 at 16:39, Charles Blackwell <


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Charles Blackwell  
View profile  
 More options Apr 29 2012, 3:52 pm
From: Charles Blackwell <charlesblackwell...@gmail.com>
Date: Sun, 29 Apr 2012 12:52:24 -0700 (PDT)
Local: Sun, Apr 29 2012 3:52 pm
Subject: Re: Hashing Password in CakePHP 2.1

I only have a form to create new users, so it would always be true.

My code was

public function beforeSave($created){
if($created)
  $this->data['User']['password'] =
AuthComponent::password($this->data['User']['password']);
return true;

}

It didn't like that and I was still getting the error.
Notice (8): Undefined index: password [APP\Model\User.php, line 7]

Charles


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tilen Majerle  
View profile  
 More options Apr 29 2012, 3:53 pm
From: Tilen Majerle <tilen.maje...@gmail.com>
Date: Sun, 29 Apr 2012 21:53:50 +0200
Local: Sun, Apr 29 2012 3:53 pm
Subject: Re: Hashing Password in CakePHP 2.1

you got this error because key 'password' didn't exists :)
--
Lep pozdrav, Tilen Majerle
http://majerle.eu

2012/4/29 Charles Blackwell <charlesblackwell...@gmail.com>


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »