Hashing Password in CakePHP 2.1
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:
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.
You do not have the permission required to post.
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>
> 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. }
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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>
> 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>
>> 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. }
>> --
>> Our newest site for the community: CakePHP Video Tutorials
>> http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help
>> others with their CakePHP related questions.
>> To unsubscribe from this group, send email to
>> cake-php+unsubscribe@googlegroups.com For more options, visit this group
>> at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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 :)
On Sunday, April 29, 2012 3:30:30 PM UTC-4, MaJerle.Eu wrote:
> 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>
>> 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. }
>> -- >> Our newest site for the community: CakePHP Video Tutorials >> http://tv.cakephp.org >> Check out the new CakePHP Questions site http://ask.cakephp.org and help >> others with their CakePHP related questions.
>> To unsubscribe from this group, send email to >> cake-php+unsubscribe@googlegroups.com For more options, visit this group >> at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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.
On Sunday, April 29, 2012 3:32:21 PM UTC-4, MaJerle.Eu wrote:
> 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>
>> 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>
>>> 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. }
>>> -- >>> Our newest site for the community: CakePHP Video Tutorials >>> http://tv.cakephp.org >>> Check out the new CakePHP Questions site http://ask.cakephp.org and >>> help others with their CakePHP related questions.
>>> To unsubscribe from this group, send email to >>> cake-php+unsubscribe@googlegroups.com For more options, visit this >>> group at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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.
On Sunday, April 29, 2012 3:30:30 PM UTC-4, MaJerle.Eu wrote:
> 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>
>> 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. }
>> -- >> Our newest site for the community: CakePHP Video Tutorials >> http://tv.cakephp.org >> Check out the new CakePHP Questions site http://ask.cakephp.org and help >> others with their CakePHP related questions.
>> To unsubscribe from this group, send email to >> cake-php+unsubscribe@googlegroups.com For more options, visit this group >> at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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 <
charlesblackwell
... @gmail.com> wrote:
> I am still very new to PHP and Cake.
> On Sunday, April 29, 2012 3:32:21 PM UTC-4, MaJerle.Eu wrote:
>> 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>
>>> 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**>
>>>> 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->re**quest->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 >
>>>> ('quickwall@**localhost.com <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. }
>>>> --
>>>> Our newest site for the community: CakePHP Video Tutorials
>>>> http://tv.cakephp.org
>>>> Check out the new CakePHP Questions site http://ask.cakephp.org and
>>>> help others with their CakePHP related questions.
>>>> To unsubscribe from this group, send email to
>>>> cake-php+unsubscribe@**googlegroups.com<cake-php%2Bunsubscribe@googlegroups .com>For more options, visit this group at
>>>> http://groups.google.com/**group/cake-php <http://groups.google.com/group/cake-php >
>> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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 <
charlesblackwell
... @gmail.com> wrote:
> 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.
> On Sunday, April 29, 2012 3:30:30 PM UTC-4, MaJerle.Eu wrote:
>> 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**>
>>> 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->re**quest->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 >
>>> ('quickwall@**localhost.com <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. }
>>> --
>>> Our newest site for the community: CakePHP Video Tutorials
>>> http://tv.cakephp.org
>>> Check out the new CakePHP Questions site http://ask.cakephp.org and
>>> help others with their CakePHP related questions.
>>> To unsubscribe from this group, send email to
>>> cake-php+unsubscribe@**googlegroups.com<cake-php%2Bunsubscribe@googlegroups .com>For more options, visit this group at
>>> http://groups.google.com/**group/cake-php <http://groups.google.com/group/cake-php >
>> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group
> at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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
On Sunday, April 29, 2012 3:41:31 PM UTC-4, Thiago Belem wrote:
> $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 <
> charlesblackwell... @gmail.com> wrote:
>> 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.
>> On Sunday, April 29, 2012 3:30:30 PM UTC-4, MaJerle.Eu wrote:
>>> 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**>
>>>> 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->re**quest->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 >
>>>> ('quickwall@**localhost.com <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. }
>>>> -- >>>> Our newest site for the community: CakePHP Video Tutorials >>>> http://tv.cakephp.org >>>> Check out the new CakePHP Questions site http://ask.cakephp.org and >>>> help others with their CakePHP related questions.
>>>> To unsubscribe from this group, send email to
>>>> cake-php+unsubscribe@**googlegroups.com<cake-php%2Bunsubscribe@googlegroups .com>For more options, visit this group at >>>> http://groups.google.com/**group/cake-php <http://groups.google.com/group/cake-php >
>>> -- >> Our newest site for the community: CakePHP Video Tutorials >> http://tv.cakephp.org >> Check out the new CakePHP Questions site http://ask.cakephp.org and help >> others with their CakePHP related questions.
>> To unsubscribe from this group, send email to
>> cake-php+unsubscribe@googlegroups.com For more options, visit this group >> at http://groups.google.com/group/cake-php
You must
Sign in before you can post messages.
You do not have the permission required to post.
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>
> $this->data['User']['password']
You must
Sign in before you can post messages.
You do not have the permission required to post.